Posts

Showing posts from July, 2019

Decoding numeric string to alphabets.

Image
Problem Given a string of integers returns the number of ways to decode integers back to Alphabets using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 examples: input = 199 output = 2 explanation: 1-> 9 -> 9 (AII) 11-> 9 (KI) input = 11 output = 1 explanation: 1->1 (AA) 11 (K)

Finding the shortest path from start to end word given list of words

Given list of array and start and end word as below:    ["hot", "hit", "his", "hat"] Start word: "hot" End word: "his" Find the shortest sequence starting the from start and ending the with end word. The rule is, from the start word, each time you can only change one character, and only use words from the given set, find out how to get to the end word. In the above example, the sequence is:    hot  -> hit -> his (hat is not used) for this example: start = 'his' end = 'hit' input = ["his", "has", "hit", "hat"] we can find this: his -> has -> hat -> hit. However: his -> hit is the sorted path.

Checking whether interval (a,b) is covered given 1-D list of coordinates

Question Given 1-D list of co-ordinates determine if interval (a,b) is covered Ex - [(2,5), (5,7),(1,4)] and interval = (1,6) return true Explanation - Points 1 to 6 lies in list of interval given 1 to 4. 2 to 5 and 5 to 7. [(1,4),(6,7),(2,5)] and interval - (1,6) return false Explanation - Distance between 5 to 6 is not covered in the list given so return false

Power of 3 problem

Problem Write function to determine if given unsigned 32-bit number is a power of 3     int is_power_of_3(uint32_t n)

Design the BigString class

Problem [Revised] Design the BigString class which has the following public methods // method to add char to the word at the specified index. void insert (char c, int pos) {   // } //method to return the word at the specified index. word * search(int index) { // } Example) insert('a', 0); ==> [a] insert('b', 0); ==> [ba] insert(' ', 0); ==> [ ba] insert('c', 0); ==> [c ba] insert('e', 11) ==> [c ba       e] insert('f', 8); ==> [c ba    f   e] insert('o', 3)  ==> [c boa    f   e] insert('u', 10) ==> [c boa    fu   e] search(0) ==>  c search(1) ==>  boa search(2) ==>  fu search(3) ==>  e

Write serialize and deserialize functions for an array of strings

Problem Write 2 functions to serialize and deserialize an array of strings. strings can contain any Unicode character. Do not worry about string overflow. input = ['abdcd', '4agasd-dsfafdas', 'hi there I love you'] output = serialize(input) deserialize(output) = ['abdcd', '4agasd-dsfafdas', 'hi there I love you']

Finding the shortest sequence containing the keywords (Minimum window subsequence problem)

Problem Find the shortest string [] containing the keyword inside Example, Words: sky cloud google search sky work blue Keywords: sky blue Return: sky work blue