File tree Expand file tree Collapse file tree 5 files changed +50
-1
lines changed
main/java/in/ashwanik/dcp/problems/p91_120/p116
test/java/in/ashwanik/dcp/problems/p91_120/p116 Expand file tree Collapse file tree 5 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -1854,7 +1854,7 @@ same structure and node values with a subtree of s. A subtree of s is a tree
18541854consists of a node in s and all of this node's descendants. The tree s could
18551855also 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.
Original file line number Diff line number Diff 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| --| --| --| --| --| --| --| --| --| --| --| --| --| --| --|
Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments