Skip to content

Commit caa2ca1

Browse files
updated
1 parent eb68eba commit caa2ca1

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

AllQuestions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ tree.
612612
The power set of a set is the set of all its subsets. Write a function that,
613613
given a set, generates its power set.
614614

615-
For example, given the set {1, 2, 3}, it should return {{}, {1}, {2}, {3}, {1,
616-
2}, {1, 3}, {2, 3}, {1, 2, 3}}.
615+
For example, given the set `{1, 2, 3}`, it should return `{{}, {1}, {2}, {3}, {1,
616+
2}, {1, 3}, {2, 3}, {1, 2, 3}}`.
617617

618618
You may also use a list or array to represent a set.
619619

build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ repositories {
1313

1414
dependencies {
1515
testImplementation('org.junit.jupiter:junit-jupiter:5.4.2')
16+
17+
1618
}

src/main/java/in/ashwanik/dcp/problems/p91_120/p99/Solution.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ int getLongestConsecutiveSequenceLength(int[] numbers) {
1717
int max = 0;
1818
for (int n : numbers) {
1919
int k = n;
20-
int count = 1;
21-
while (set.contains(++k)) {
22-
count++;
20+
if (!set.contains(k - 1)) {
21+
int count = 1;
22+
while (set.contains(++k)) {
23+
count++;
24+
}
25+
max = Math.max(max, count);
2326
}
24-
max = Math.max(max, count);
2527
}
2628
return max;
2729
}

0 commit comments

Comments
 (0)