Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1dfc9e9

Browse files
p203
1 parent 0c8d545 commit 1dfc9e9

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

‎AllQuestions.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3202,7 +3202,7 @@ Write a program that checks whether an integer is a palindrome. For example, 121
32023202
is a palindrome, as well as 888. 678 is not a palindrome. Do not convert the
32033203
integer into a string.
32043204

3205-
## Problem-203:waxing_crescent_moon:
3205+
## [Problem-203](src/main/java/in/ashwanik/dcp/problems/p181_210/p203):sunny:
32063206

32073207

32083208
> This problem was asked by Uber.

‎README.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ Solutions to the coding problems from [Daily coding problem](https://dailycoding
4141
|[P53](src/main/java/in/ashwanik/dcp/problems/p31_60/p53)|[P74](src/main/java/in/ashwanik/dcp/problems/p61_90/p74)|[P93](src/main/java/in/ashwanik/dcp/problems/p91_120/p93)|[P135](src/main/java/in/ashwanik/dcp/problems/p121_150/p135)|[P148](src/main/java/in/ashwanik/dcp/problems/p121_150/p148)|[P196](src/main/java/in/ashwanik/dcp/problems/p181_210/p196)|
4242

4343

44-
## **General (5)**
44+
## **Uber (5)**
4545
| | | | | |
4646
|--|--|--|--|--|
47-
|[P128](src/main/java/in/ashwanik/dcp/problems/p121_150/p128)|[P129](src/main/java/in/ashwanik/dcp/problems/p121_150/p129)|[P147](src/main/java/in/ashwanik/dcp/problems/p121_150/p147)|[P151](src/main/java/in/ashwanik/dcp/problems/p151_180/p151)|[P153](src/main/java/in/ashwanik/dcp/problems/p151_180/p153)|
47+
|[P2](src/main/java/in/ashwanik/dcp/problems/p1_30/p2)|[P87](src/main/java/in/ashwanik/dcp/problems/p61_90/p87)|[P160](src/main/java/in/ashwanik/dcp/problems/p151_180/p160)|[P166](src/main/java/in/ashwanik/dcp/problems/p151_180/p166)|[P203](src/main/java/in/ashwanik/dcp/problems/p181_210/p203)|
4848

4949

50-
## **Uber (4)**
51-
| | | | |
52-
|--|--|--|--|
53-
|[P2](src/main/java/in/ashwanik/dcp/problems/p1_30/p2)|[P87](src/main/java/in/ashwanik/dcp/problems/p61_90/p87)|[P160](src/main/java/in/ashwanik/dcp/problems/p151_180/p160)|[P166](src/main/java/in/ashwanik/dcp/problems/p151_180/p166)|
50+
## **General (5)**
51+
| | | | ||
52+
|--|--|--|--|--|
53+
|[P128](src/main/java/in/ashwanik/dcp/problems/p121_150/p128)|[P129](src/main/java/in/ashwanik/dcp/problems/p121_150/p129)|[P147](src/main/java/in/ashwanik/dcp/problems/p121_150/p147)|[P151](src/main/java/in/ashwanik/dcp/problems/p151_180/p151)|[P153](src/main/java/in/ashwanik/dcp/problems/p151_180/p153)|
5454

5555

5656
## **Stripe (4)**
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Suppose an array sorted in ascending order is rotated at some pivot unknown to
2+
you beforehand. Find the minimum element in O(log N) time. You may assume the
3+
array does not contain duplicates.
4+
5+
For example, given [5, 7, 10, 3, 4], return 3.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package in.ashwanik.dcp.problems.p181_210.p203;
2+
3+
class Solution {
4+
5+
//// 5 7 10 15 17 3 4
6+
7+
/// 10 3 4 5 6 7 8
8+
9+
int getMinimum(int[] array) {
10+
if (array == null || array.length == 0) {
11+
return -1;
12+
}
13+
14+
int low = 0;
15+
int high = array.length - 1;
16+
int mid = 0;
17+
while (low <= high) {
18+
mid = low + (high - low) / 2;
19+
20+
if (mid + 1 < array.length && array[mid] > array[mid + 1]) {
21+
return array[mid + 1];
22+
}
23+
24+
if (array[mid] > array[high]) {
25+
low = mid + 1;
26+
} else {
27+
high = mid - 1;
28+
}
29+
}
30+
return array[mid];
31+
}
32+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package in.ashwanik.dcp.problems.p181_210.p203;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class SolutionTest {
8+
@Test
9+
void testGetMinimum() {
10+
assertEquals(3, new Solution().getMinimum(new int[]{5, 7, 10, 3, 4}));
11+
assertEquals(3, new Solution().getMinimum(new int[]{10, 3, 4, 5, 6, 7, 8}));
12+
assertEquals(3, new Solution().getMinimum(new int[]{5, 7, 10, 17, 17, 18, 3, 4}));
13+
}
14+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /