Java Coding Challenges
This repo will contain the solutions using Java 8 for challenges found on:
- Books
- Hacker Rank
- Codility
- CodeFights
Challenges
Codility
Can we sort an array with a simple swap?
We need to write a function that will return true if we can sort an array swapping only two elements.
Mystery number
We need to write a function to shuffle the digits on a number on a particular way. The first char with the last char, the second char with the second to last char until we use all the digits.
Find the longest sentence.
We have phrases composed by sentences and each of this sentences contain words. We need to write a function that will give us the number of words on the longest sentence. The sentences are separated by "?", "!", "." and the words simply by spaces (" ").
Binary Gap
A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.
CyclicRotation
We need to perform an array shift to the right a given number of times.
Frog Jumps
A little frog wants to cross to the other side of the river, but it can only jump to the leaves that fall on the water and only then the complete path from 0 to target has all required leaves. Given the starting position 0, and a non empty array indexed by each second and the position of the leaf. Find the earliest time when the frog can jump all the way from 0 to the target position.
Permutation Check
We need to perform a check on an array to see if it's a permutation of N elements where N original size of the array.
Note: A permutation is a sequence containing each element from 1 to N once, and only once.
Max Counter (Counter Operations)
We need to calculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum.
Minimum Number of Plays on a Casino (*)
A guy walks out of a Casino with N chips. We know that he played W times an all in. We need to find the minimum number of plays he could play on the casino to earn those N chips.
Factory of Shoes (*)
We have a line of shoes composed of Left (L) and Right (R) shoes. We want to assign a group of workers to work on the shoes, but we need to guarantee that we assign each worker a group of shoes that contains the same number of L and R shoes.
Hacker Rank
Odd number generator
We need to write a function that return all the odd numbers on a range given the start and the end of the range as integers. This collection will include the start and end integers if they are odd numbers too
Books
Unique characters
We need to write a function that will tell us if all the characters on a given string are unique.
Check permutation
We need to write a function that given two strings let us find if one is a permutation of the other.
URL Friendly String
Given a String and its true length, transform the string to a URL friendly string by replacing the spaces by %20
Note: We can assume that the string contains a length that allow us to store the additional chars without having to allocate a new string.
Others (Challenges proposed by Friends or Solved on hackatons)
Recursively reverse a string
Given a string, reverse the characters and return
Find the first char that repeats it self on a given string
Given a string, find the first chat that repeats it self.