Sunday, April 22, 2018
Replace where ever question mark is there in a string with 0 and 1 with all the patterns created.
Example : input string "a??b?"
outputs are a00b0,a00b1,a01b0, a01b1... like that all possiblities
Here is the sample code for same
Wednesday, April 11, 2018
Print out an imutable singly linked list in reverse in linear time (O(n)) and less than linear space (space<(O(n))
Here is a solution for one pass reversing of singly linked list
Monday, April 9, 2018
String replacement with characters from Map to generate all possible combinations
String replacement with characters from Map to generate all possible combinations
Given a hashmap M which is a mapping of characters to arrays of replacement characters, and an input string S, return an array of all possible combinations of S (where any character in S can be substituted with one of its substitutes in M, if it exists).
What is the time complexity? What is the space complexity? Can you optimize either?
Example input:
M = { f: [F, 4], b: [B, 8] }
S = fab
Expected output:
[FaB, Fa8, 4aB, 4a8]
Sunday, April 8, 2018
String pattern generation based on Dictionary entries
Given a string as input, return the list of all the possible patterns:
'''
{ "1" : ['A', 'B', 'C'],
"2" : ['D', 'E'],
"12" : ['X'],
"3" : ['P', 'Q'] }
'''
Example if input is "123", then output is ["ADP","ADQ","AEP","AEQ","BDP","BDQ","BEP","BEQ","CDP","CDQ","CEP","CEQ","XP","XQ"]
Saturday, April 7, 2018
Merging overlapping lists
You are given two lists of intervals, A and B.
In A, the intervals are sorted by their starting points. None of the intervals within A overlap.
Likewise, in B, the intervals are sorted by their starting points. None of the intervals within B overlap.
Return the intervals that overlap between the two lists.
Example:
A: {[0,4], [7,12]}
B: {[1,3], [5,8], [9,11]}
Return:
B: {[1,3], [5,8], [9,11]}
Return:
{[1,3], [7,8], [9,11]}
How would you do this?
Here is a solution
Monday, April 2, 2018
Passing a variable as type , using templates.
Often we may need to transfer the type itself to a function. Here is the implementation done using an example for determining the size of the variable type using templates. You cannot do this normal way as setting type is a compile time activity. If you use templates you can defer this action for compile time and would give you the ability to determine type during compile time. This is edited using the Visual Studio editor.
Subscribe to:
Posts (Atom)