Hi, BrowserStack recently visited our campus for written test for December placements. The written round was conducted on HackerEarth and was of 3 hours and had 2 coding questions.
QUESTION 1:
JSON Prettier:-
Write a program which takes JSON as input and gives prettified JSON
You need to read JSON from STDIN. Input gives one line of uglified JSON.
Output should be formatted JSON. Check the standard output link.
Use 2 white spaces (not‘\t’) for one indentation.
SAMPLE INPUT:
{“group” : {list : [1,2,3]}, “list” : [“a”,”b”,”c”]}
SAMPLE OUTPUT:
{
“group” : {
List : [1,2,3]
},
“list” : [“a”,”b”,”c”]
}
EXPLANATION: Input will be uglifiedjson in one line and output will be prettified format of that.
QUESTION 2:
Given a string and a regular expression pattern, give the number of times the pattern occurs in the string. RegEx example means as follows:
. – 2 occurrences of the previous character
+ – 4 occurrences of the previous character
* – more than 5 occurrences of the previous character
Sample Input:
5
aaaaaannndnnnnnnfffhfhhgjjjwkkkllclc
a.
n+
a*
an.
a.d.
Sample Output:
5
3
2
1
0
Hi, for JsonPrettier, did they allow to use JSONObject or GSON class? Or did you have to actually parse the whole thing character-by-character?