Friday, June 21, 2019
Monday, June 10, 2019
Sunday, March 3, 2019
Variable arguments in C
Variable arguments can be passed to a function in C. The best example for this is the inbuilt printf function. For printf the first argument is a character array and variable number of arguments after that.
This is implemented using macros within the stdarg header. When parameters are passed to a function , its copied to a stack created for that function. va_list and va_arg and va_end are macros which help traverse thru this stack. This is partial implementation of your own printf function.
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"]
Subscribe to:
Posts (Atom)