Skip to content

Commit 994647e

Browse files
p116
1 parent 75eb62a commit 994647e

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

AllQuestions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ same structure and node values with a subtree of s. A subtree of s is a tree
18541854
consists of a node in s and all of this node's descendants. The tree s could
18551855
also be considered as a subtree of itself.
18561856

1857-
## Problem-116:waxing_crescent_moon:
1857+
## [Problem-116](src/main/java/in/ashwanik/dcp/problems/p91_120/p116):sunny:
18581858

18591859

18601860
> This problem was asked by Jane Street.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ Solutions to the coding problems from [Daily coding problem](https://dailycoding
138138
|[P106](src/main/java/in/ashwanik/dcp/problems/p91_120/p106)|
139139

140140

141+
## **Jane Street (1)**
142+
| |
143+
|--|
144+
|[P116](src/main/java/in/ashwanik/dcp/problems/p91_120/p116)|
145+
146+
141147
# [Pending Questions](PendingQuestions.md):17
142148
| | | | | | | | | | | | | | | |
143149
|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Generate a finite, but an arbitrarily large binary tree quickly in O(1).
3+
4+
That is, generate() should return a tree whose size is unbounded but finite.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package in.ashwanik.dcp.problems.p91_120.p116;
2+
3+
import in.ashwanik.dcp.common.TreeNode;
4+
5+
import java.util.Random;
6+
7+
class Solution {
8+
9+
private Random random;
10+
11+
Solution() {
12+
random = new Random();
13+
}
14+
15+
TreeNode<Integer> generate() {
16+
TreeNode<Integer> root = new TreeNode<>(0);
17+
if (random.nextBoolean()) {
18+
root.setLeft(generate());
19+
}
20+
if (random.nextBoolean()) {
21+
root.setRight(generate());
22+
}
23+
return root;
24+
}
25+
26+
27+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package in.ashwanik.dcp.problems.p91_120.p116;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertNotNull;
6+
7+
public class SolutionTest {
8+
@Test
9+
void testGenerate() {
10+
assertNotNull(new Solution().generate());
11+
}
12+
}

0 commit comments

Comments
 (0)