Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
4
votes
2answers
462 views
Hackerrank Submission Optimisation for Melodious Password
Given question from Hackerrank:
a password consists of exactly n lowercase English letters.
the password is melodious, meaning that consonants can only be next to
...
2
votes
1answer
41 views
ADDREV - Adding Reversed Numbers
I've finished ADDREV challenge but I'm still not happy with my current solution. How can I still make my solution efficient without using the built-in std::reverse()...
-7
votes
0answers
25 views
Write a python program to compute the optimal sequence alignment of two DNA strings using Edit Distance algorithm [on hold]
A genetic sequence is a string formed from a four-letter alphabet {Adenosine (A), Thymidine (T), Guanosine (G), Cytidine (C)} of biological macromolecules referred to together as the DNA bases. A gene ...
12
votes
2answers
600 views
Breadth First Search to find connected primes
I've been working through the British Informatic Olympiad's 2016 Paper, and I've been struggling with some of the larger cases for question 3, specifically the larger cases on the mark scheme (the 3 ...
11
votes
2answers
2k views
“Longest Collatz sequence” in C slower than in Python 3
This tight-looped memoization-less C solution to Project Euler's problem 14 seems efficient, but ran much slower than a similarly trivial Python 3 program. For the desired ...
7
votes
3answers
1k views
Leetcode 125. Valid Palindrome (better performance?)
Problem statement
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama" is a ...
4
votes
1answer
83 views
Leetcode 125. Valid Palindrome
Problem statement
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama" is a ...
7
votes
4answers
841 views
Project Euler problem 14 (longest Collatz sequence) in Swift 3
I was trying to solve Project Euler:Problem 14 using Swift 3, but it takes ages to give me an answer, which is a sign that my code is absolute garbage performance-wise. What could I do to increase the ...
3
votes
1answer
80 views
C# greedy algorithm to pick activities that do not clash with each other (corrected)
My task is the greedy algorithm:
The activity selection problem is characteristic to this class of problems, where the goal is to pick the maximum number of activities that do not clash with each ...
6
votes
2answers
546 views
Singly Linked List “Strange sorting” exercise
I'm currently working through "Algorithms in java" by Robert Sedgewick (3rd edition, german version) on my own and am trying to solve one of the exercises there.
One of these involves taking a ...
5
votes
0answers
29 views
Kattis problem Amanda Lounges
I wrote this solution to Kattis problem Amanda Lounges in Scala. TL;DR: It's a graph theory problem where I read in a list of edges from stdin and try to compute the minimum number of nodes that ...
8
votes
1answer
106 views
Hacker Rank: Journey to the Moon (Graph Theory)
I am attempting to complete the "Journey to the Moon" problem described below:
https://www.hackerrank.com/challenges/journey-to-the-moon
There are N trained astronauts numbered from 0 to N-1. But ...
8
votes
1answer
84 views
Project Euler 11: Largest product in a grid, Python3
Project Euler #11
What is the greatest product of four adjacent numbers in the same
direction (up, down, left, right, or diagonally) in the 20×20 grid?
I've seen some of the solutions of the ...
5
votes
1answer
87 views
Hackerrank: Lucky Number Eight (Dynamic Programming)
Problem statement
Given an n-digit positive integer, count and print the number of subsequences formed by concatenating the given number's digits that are divisible by 8. As the result can be large,...
4
votes
2answers
40 views
Perform basic string compression using the counts of repeated characters
I managed to implement this question from Cracking the Coding Interview:
Implement a method to perform basic string compression using the counts
of repeated characters. For example, the string <...
6
votes
3answers
75 views
Kattis Challenge - Recount - count who has the most votes in a list of names
I am attempting to solve the Kattis problem Recount.
The recent schoolboard elections were hotly contested: a proposal to swap school start times for elementary and high school students, a ...
4
votes
2answers
105 views
Hackerrank: Gridland Metro
Problem statement
The city of Gridland is represented as an n X m matrix where the rows are numbered from 1 to ...
2
votes
1answer
68 views
Hackerrank: KnightL on a Chessboard
Problem statement
KnightL is a chess piece that moves in an L shape. We define the possible moves of KnightL(a,b) as any movement from some position (x1, y1) to ...
10
votes
1answer
89 views
Check consistency of statements, with fuzzy rhyme matching (Kattis “Mårten's Theorem” challenge)
I wrote a review for Check consistency of a list of statements, with fuzzy rhyme matching, which basically required me to try writing my own solution to fully understand the challenge. So, I thought ...
7
votes
1answer
39 views
Check consistency of a list of statements, with fuzzy rhyme matching
I made a program today that solves the following problem on a programming competition site (open.kattis.com): Check if all statements with the following format X is Y or X not Y are consistent. X and ...
3
votes
2answers
76 views
Swift HackerRank Missing Numbers Challenge
I'm attempting to solve the "Missing Numbers" challenge on HackerRank where I'm tasked with finding missing elements comparing two arrays.
Foundation's ...
6
votes
2answers
129 views
UVA 100: “The 3n + 1 problem”
I’ve solved UVA Problem 100: The 3n + 1 problem . In short, the task was to write a program that calculates a maximum of Collatz sequence lengths for any given range of starting values.
My program:
<...
6
votes
1answer
84 views
Implementing pow(x,n)
I solved this leetcode problem.
The question is.
Implement pow(x, n).
This is my solution.
...
12
votes
3answers
752 views
Worded Mastermind game in Python
Just completed a /r/dailyprogrammer challenge. Challenge #238 to be precise.
A Github repository with the wordbank.txt is available here.
...
7
votes
3answers
78 views
Project Euler+ #35 - Summing circular primes less than N
Overview
The following code is a solution for a Project Euler+ problem on Hackerrank. A circular prime is a prime number whose rotations are also prime. For example, 197 is a circular prime since it ...
-3
votes
2answers
132 views
Finding repeated letters in a list of words [closed]
John has discovered various rocks. Each rock is composed of various
elements, and each element is represented by a lowercase Latin letter
from 'a' to 'z'. An element can be present multiple times ...
0
votes
0answers
38 views
Ternary tree preoder traversal (recursive implementation)
Problem statement:
Print out to console the ternary tree preorder traversal. Suppose that the tree can have at most 3 children, left, middle and right. Preorder traversal is to visit the middle ...
3
votes
1answer
50 views
Ricochet Challenge: Robust IO and working with different types of numbers in Haskell
Background
I've tried to solve /r/DailyProgrammer Challenge #303 [Easy]: Ricochet (summarised below) in Haskell. The code below is now the second Haskell script I've ever written, so I'd consider ...
4
votes
1answer
46 views
Counting the occurrences of bank account numbers for SPOJ challenge
I am solving a problem on SPOJ and am currently unsatisfied with my submission time, given that my fastest time is 0.28s (which ranks me 123/5037) and the leading submission is 0.04s.
The problem is ...
1
vote
0answers
84 views
Hackerrank > Woman's CodeSprint 2 > stone division, Revisited ( recursive function)
Problem statement
You have a pile of n stones that you want to split into multiple piles, as well as a set, S, of ...
3
votes
1answer
50 views
Extract index of first unique element in large array in Swift
I'm using the following code to return the first index of a unique character in a large String. It works fine until I get to large strings, where it times out.
Is ...
3
votes
1answer
84 views
Remove Duplicates from Array in Swift 3.0
I ran the following code through a Leetcode.com challenge and it says the runtime for the test cases is 119ms, which puts it at the back of the pack performance wise.
The goal is to remove duplicates ...
0
votes
1answer
51 views
Adding k to many elements in a sequence
First line will contain two integers N and M separated by a single space. Then next lines will contain three integers a, b and k separated by a single space. N is the length of the sequence. M is the ...
3
votes
2answers
105 views
Dijkstra's algorithm in JavaScript
I'm trying to implement Dijkstra's algorithm to find the shortest path. This is from a challenge on CodeWars.
In this scenario there is a map:
...
4
votes
2answers
68 views
Maximum path sum of triangle of numbers
I have implemented the maximum path sum of a triangle of integers (problem 18 in project euler) and I am wondering how I can improve my solution. My solution is below:
...
4
votes
4answers
107 views
Find the highest prime factor for given number
My code works for some smaller inputs but larger numbers causes it to hang (when running with node)
...
8
votes
2answers
162 views
Create two vehicles, move them on a grid based on user input
I have a grid and a class Vehicle, which will have starting point(X, Y on the grid) and direction(one of N,E,S,W) taken from user and there will be commands, ...
5
votes
2answers
1k views
Euler Project problem #3
Problem: What is the largest prime factor of the number 600851475143?
Hi, I'm really new with Python. Can anyone give me some feedback for this code? it seem to produce the correct answer
...
4
votes
1answer
48 views
Path Finder Maze
The goal of my code was to find all possible moves from each open position in the maze (@moves_hash), assign it a value for how many moves it would take to get to ...
8
votes
0answers
30 views
Parallelogram Connectivity
This is the hardest problem from the HackerRank contest University CodeSprint 2.
Problem Statement
Consider a hexagonal board with \$ n \times m \$ cells where each cell is black or white. The ...
1
vote
0answers
130 views
Leetcode 317: Shortest distance from all buildings
Problem statement:
You want to build a house on an empty land which reaches all buildings in the shortest amount of distance. You can only move up, down, left and right. You are given a ...
0
votes
0answers
19 views
Texplode KotH controller
I am creating a KotH challenge for Programming Puzzles and Code Golf. Other site users will write programs that play Texplode (a version of this game on a square grid). The program works, but I don't ...
4
votes
1answer
64 views
O Levels 2210 Computer Science Pre-Release: Senior Citizens Trip Organizer
Can anyone go over the code and suggest any edits and/or efficient solutions?
Attached below are the provided tasks and their solutions. The task is copyright of Cambridge International Examinations.
...
3
votes
1answer
108 views
Hackerrank: Prefix neighbors
Problem statement
Mark has a dictionary, S, containing n distinct strings. He defines the benefit value of a string
as the ...
1
vote
2answers
95 views
Project Euler #11 - Largest product in a grid C++
https://projecteuler.net/problem=11
Any thoughts? Also, when measuring with chrono it takes supposedly 4 ms to compute, is this reliable value? Previous problems took little longer to compute so I'm ...
5
votes
4answers
232 views
Optimizing Bingo Caller Method
I am dong a competitive programming problem I have passed all the tests.
but my program times out. I need help optimizing my code so it can run faster.
Task:
Finish method: ...
5
votes
1answer
80 views
My solution to a competitive programming problem (UVA 10189, Minesweeper)
This is one of my first competitive programming solutions. The problem it solves is described here; basically, you get a series of grids ("fields"), where . means "...
1
vote
1answer
118 views
Codewars “Consecutive strings” kata
The challenge description is as follows:
You are given an array strarr of strings and an integer k. Your task is to return ...
4
votes
1answer
83 views
Word Search in LeetCode
I solved this programming challenge:
Given a 2D board and a word, find if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent
cell, where "...
4
votes
1answer
82 views
100 Doors simulation
100 Doors
100 doors is a relatively simple mathematical problem. If you have 100 doors that are initially closed, and follow this procedure:
Walk past the doors 100 times, the first time you ...