Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Problem 1 - JSON Diff Utility
- ### Write a utility to compare two JSON documents and generate the differences.
- **Example -**
- For two json documents - `clark1.json` and `clark2.json`.
- `clark1.json`
- ```
- {
- "name": "Clark Kent",
- "age":"33",
- "work":"Daily Planet",
- "friends": ["Lana Lang"]
- }
- ```
- and
- `clark2.json`
- ```
- {
- "name": "Clark Kent",
- "age":"34",
- "work":"Daily Planet",
- "associations": ["Justice League"]
- }
- ```
- **Diffs (result)**
- 1. Property `age` is changed from 33 to 34
- 2. New property `associations` is added with value - `["Justice League"]`
- 3. Property `friends` is deleted
- >**Note:** You can define your own format/type to represent a diff.
- ### In addition, you should be able to create a new JSON document from a base JSON document and a list of differences.
- **Example -**
- For a json document - `clark1.json`
- ```
- {
- "name": "Clark Kent",
- "age":"33",
- "work":"Daily Planet",
- "friends": ["Lana Lang"]
- }
- ```
- And a list of diff -
- 1. Property `age` is changed from 33 to 34
- 2. New property `associations` is added with value - `["Justice League"]`
- 3. Property `friends` is deleted
- You should be able to create a new JSON -
- ```
- {
- "name": "Clark Kent",
- "age":"34",
- "work":"Daily Planet",
- "associations": ["Justice League"]
- }
- ```
- **APIs**
- `List<Diff> diff(String jsonA, String jsonB)`
- `String patch(String jsonA, List<Diff>)`
- ---
- # Problem 2 - Expression evaluator
- You will be provided with two strings - `expression` and `values`. `expression` represents a mathematical expression with some variables. `values` will provide the values of the variables in the expression in the following format -
- `key=value;...;key=value`
- **Example 1-**
- `expression` - `"x^2 + 2x + 1"`
- `values` - `"x=5"`
- *Result* = 36
- **Example 2 (with a trigonometric function)-**
- `expression` - `"x^2 + 2x + 1 + sin(y)"`
- `values` - `"x=5;y=π/2"`
- **Result** = 37
- **Example 3 (with a decimal number)-**
- `expression` - `"x^2 + 2.5y + 1 + sin(z)"`
- `values` - `"x=5;y=4;z=π/2"`
- **Result** = 37
- ### Symbols and meanings
- 1. `sin` - sine trigonometric function
- 2. `cos` - cosine trigonometric function
- 3. `tan` - tangent trigonometric function
- 4. `log` - logarithm function
- 5. `x^y` - `x` raised to power `y`
- 6. `xy` - product of `x` and `y`
- 7. `x/y` - `x` divided by `y`
- 8. `x+y` - sum of `x` and `y`
- 9. `x-y` - difference of `x` and `y`
- 10. `()` - parenthesis
- 11. `π` - Mathematical constant PI
- **APIs**
- `double evaluate(String expression, String values)`
- ---
- ### Completion Date - `October 31, 2019`
- ### Programming Language - `Java`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement