Open In App

BrowserStack Interview Experience | Set 2 (Coding Questions)

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

PROFILE: SOFTWARE ENGINEER
PAPER DURATION: 3 hours
NO. OF QUESTIONS: 2 (20 marks each)
MAXIMUM MARKS: 20*2 = 40 marks

QUESTION 1:
JSON Prettier:-

Write a program which takes JSON as input and gives prettified JSON

  1. You need to read JSON from STDIN. Input gives one line of uglified JSON.
  2. Output should be formatted JSON. Check the standard output link.
  3. 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:

XML parse plus series computation

Evaluate an expression given in XML format. Keys will be Expr- contains the entire expression. Elem – contains the digit, sum, Prod- contains two or more keys whose evaluation needs to be summed or multiplied respectively. Sub will contain 2 keys or more, where the second key onwards will have to be subtracted from the first one. Div- will contain 2 keys in which first key will need to be divided by second.

 

SAMPLE INPUT:

<expr>

<sum>

<elem>4</elem>

<elem>6</elem>

<elem>7</elem>

<elem>3</elem>

</sum>

</expr>

 

SAMPLE OUTPUT:
20

EXPLANATION:

Input will be xml file through standard input. End of xml file marked by </expr>.


Last Updated : 02 Jan, 2016
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads