Coding Challenges

Browse by Tag

Browse All Challenges

Check if all chars in a string are unique

Write a function that determines if each characters in a String appear no more than once.

Related Tags: Strings

3 ways to check if a value is prime

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number. Given an input value check if it's a prime.

Related Tags: Math

Check if a string is an anagram

Write a function that checks to see if two Strings are anagrams of each other. Hint: an anagram of a word is one that has the same characters in it, but in a different sequence e.g. "listen" and "silent."

Related Tags: Strings

Cheryl's Birthday

Albert and Bernard became friends with Cheryl, and they want to know when her birthday is. Cheryl gives them a list of 10 possible dates.

May 15May 16May 19
June 17June 18
July 14July 16
August 14August 15August 17

Cheryl then tells Albert and Bernard separately the month and day of her birthday respectively.

I don't know when Cheryl's birthday is, but I know that Bernard does not know too.
At first I don't know when Cheryl's birthday is, but I know now.
Then I also know when Cheryl's birthday is.

So when is Cheryl's birthday?

Related Tags: Brain Teasers

Double base palindrome

The decimal number 585 = 1001001001 (binary) is palindromic in both bases.
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.

Related Tags: Arrays Strings

First 100 of Fibonacci

Write a function that computes the list of the first 100 Fibonacci numbers.

Related Tags: Arrays

Finding all prime factors

Given a number, return all the prime factors and their corresponding number of occurrences.

Related Tags: Math


Write a program that prints the numbers from 1 to 100. But for multiples of three print "fizz" instead of the number and for the multiples of five print "buzz". For numbers which are multiples of both three and five print "fizzbuzz." Apparently this question is used to weed out 99.5% of candidates. Be sure to know this one!

Related Tags: Coding

Generating a list of primes less than n

Write a function that returns the list of all primes less than n.

Related Tags: Arrays Lists

Project Euler Problem 46: Goldbach's other conjecture

It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square. For example,

9 = 7 + 2 x 12
15 = 7 + 2 x 22
21 = 3 + 2 x 32
25 = 7 + 2 x 32
27 = 19 + 2 x 22

It turns out the conjecture was false. What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?

Related Tags: Math

Project Euler Problem 12: Highly divisible triangular number

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

Let us list the factors of the first seven triangle numbers:

1: 1
3: 1,3
6: 1,2,3,6
10: 1,2,5,10
15: 1,3,5,15
21: 1,3,7,21
28: 1,2,4,7,14,28

We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?

Related Tags: Math

Index of a substring

Write a function that returns the index of where a substring begins within a given string. Return -1 if it doesn't exist.

Related Tags: Strings

Integer Right Triangles

If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120: {20,48,52}, {24,45,51}, and {30,40,50}.

Related Tags: Math

Checking if Palindrome

Define a method that checks if a given singly Linked List is a palindrome.

Related Tags: Linked Lists

Removing Duplicates from a Linked List

Remove all duplicates that occur in a linked list.

Related Tags: Linked Lists

Reversing a Linked List

Reverse any given Linked List.

Related Tags: Linked Lists

Longest Palindrome Substring in a String

Find the longest palindrome substring that exists within a string.

Related Tags: Bioinformatics Strings

Odd ball out

You are given 9 balls. 8 of them weigh the same while 1 is heavier than the others. How can you determine which ball is the odd one out using just two comparisons?

Related Tags: Brain Teasers

Selecting the first non-repeating character

Write a function that finds the first non-repeated character in a String.

Related Tags: Strings

Number of canoes needed

If a canoe can hold 2 kids and a maximum weight of 150 pounds, write a function that returns the minimum number of canoes needed

Related Tags: Coding

Printing all permutations

Print all permutations of a String iteratively.

Related Tags: Strings

Project Euler Problem 27: Quadratic Primes

Euler discovered the remarkable quadratic formula:

n2 + n + 41

It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 402 + 40 + 41 = 40(40 + 1) + 41 is divisible by 41, and certainly when n = 41, 412 + 41 + 41 is clearly divisible by 41.

The incredible formula  n2 − 79n + 1601 was discovered, which produces 80 primes for the consecutive values n = 0 to 79. The product of the coefficients, −79 and 1601, is −126479.

Considering quadratics of the form:

n² + an + b, where |a| < 1000 and |b| < 1000

where |n| is the modulus/absolute value of ne.g. |11| = 11 and |−4| = 4

Find the product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n = 0.

Related Tags: Math

Removing one character

Write a method that will remove any given character from a string.

Related Tags: Strings

Largest element in a list

Write a function that returns the largest item in a list.

Related Tags: Arrays Lists

Reverse a String

Write a function that reverses a string in place.

Related Tags: Strings

Rotate a 2d array in place

Rotate a 2d array in place.

Related Tags: Arrays Coding

Checking if a String is a Palindrome

Implement a method that checks whether a string is a palindrome or not.

Related Tags: Strings

Sum with for-loop, while-loop and recursion

Write three functions that compute the sum of the numbers in a list using a for-loop.

Related Tags: Arrays Lists