Minimum number of hops to reach end of array or beyond

Given an array of integers where each element represents the max number of steps that can be made forward from that element. Write a function to return the minimum number of jumps to reach the end of the array (starting from the first element). If an element is 0, then cannot move through that element. Example: Input: arr[] = {1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9} Output: 3 (1-> 3 -> 8 ->9) First element is 1, so can only go to 3. Second element is 3, so can make at most 3 steps eg to 5 or 8 or 9. If there is no path, return 0. Your Answer.java should implement following interface public interface NumberOfHopsInterface { public int numberOfHops(int[] array); }

Answer

Find the indices with anagram match

Given a String and a pattern find all the indices at which where we find an anagram match. For example: String : BACDGABCDA Pattern : ABCD We can find a match at {0, 5, 6} In other words, if we find 4 consecutive characters from these indices, it contains the characters needed to match the pattern. Your solution should implement the following interface: public interface AnagramSearchIndexInterface { public List<Integer> anagramSubstringSearch(String source, String pattern); }

Answer

Find if there are three elements in BST that sums up to zero

Given a binary tree, check if there are three elements in binary tree which will sum up to zero. Return true if triplet exists, if not return false. For example: 4 2 6 -5 3 In this binary tree, {-5, 2, 3} sum up to zero and you should return true. 0 -1 1 In this binary tree, {-1, 1, 0} sum up to zero and you should return true 1 -1 2 In this binary tree, there doesn't exist a triplet that sum to zero and the result should be false. Your Answer.java should implement the following interface, public interface TripletSummingToZeroInterface { public boolean doesTripletSumToZero(Node root); } Node.java (No need to submit this, just for reference) public class Node { public int nodeValue; public Node lChild; public Node rChild; }

Answer

Substring for given two chars

Given a string, determine the length of the smallest substring that contains exactly one occurrence of 'a' and one occurrence of 'b' If there are no such substrings, return 0 Input : ahhhxb Output : 6 Input : ahobpa Output : 3 Input : qqqop Output : 0

Answer



Find Max Continuous Repeating Char

Given a string, return the character that is repeated the most number of times continuously. Note: Do not count the character that occurs most overall, but count only the character that occurs most number of times continuously Note: If two characters occur the same number of times continuously, return the first such in the string. Input : AABBBC Output : B Input : AAABBB Output : A

Answer

Pattern Problem | Right angle Triangle



Output

Sample 1



Enter the limit:
5
*
==========
*
**
==========
*
**
***
==========
*
**
***
****
==========
*
**
***
****
*****

==========

Sample 2

Enter the limit:
10
*
==========
*
**
==========
*
**
***
==========
*
**
***
****
==========
*
**
***
****
*****
==========
*
**
***
****
*****
******
==========
*
**
***
****
*****
******
*******
==========
*
**
***
****
*****
******
*******
********
==========
*
**
***
****
*****
******
*******
********
*********
==========
*
**
***
****
*****
******
*******
********
*********
**********
==========