Search in Rotated Sorted Array | Problem of the Day | GeeksForGeeks

  Рет қаралды 39

Mathematics

Mathematics

Күн бұрын

Given a sorted (in ascending order) and rotated array arr of distinct elements which may be rotated at some point and given an element key, the task is to find the index of the given element key in the array arr. The whole array arr is given as the range to search.
Rotation shifts elements of the array by a certain number of positions, with elements that fall off one end reappearing at the other end.
Note:- 0-based indexing is followed & returns -1 if the key is not present.
Examples :
Input: arr[] = [5, 6, 7, 8, 9, 10, 1, 2, 3], key = 10
Output: 5
Explanation: 10 is found at index 5.
Input: arr[] = [3, 5, 1, 2], key = 6
Output: -1
Explanation: There is no element that has value 6.
Expected Time Complexity: O(log n)
Expected Auxiliary Space: O(1)
Table of Contents
0:00 Problem Statement
0:52 Solution
5:40 Example 1
9:46 Example 2 - Corner Case
12:20 Pseudo Code
15:50 Code Python
17:25 Code C++

Пікірлер: 3
@mathematics3398
@mathematics3398 Ай бұрын
class Solution: def search(self,arr,key): start = 0 end = len(arr) - 1 while start = arr[start]: end = mid - 1 else: start = mid + 1 else: if key > arr[mid] and key
@mathematics3398
@mathematics3398 Ай бұрын
class Solution { public: int search(vector& arr, int key) { int start = 0, end = arr.size() - 1; while (start = arr[start]) end = mid - 1; else start = mid + 1; } else { if (key > arr[mid] and key
@mathematics3398
@mathematics3398 Ай бұрын
Table of Contents 0:00 Problem Statement 0:52 Solution 5:40 Example 1 9:46 Example 2 - Corner Case 12:20 Pseudo Code 15:50 Code Python 17:25 Code C++
Smallest number | Problem of the Day | GeeksForGeeks
12:17
Mathematics
Рет қаралды 59
Big O Notation - Full Course
1:56:16
freeCodeCamp.org
Рет қаралды 545 М.
No empty
00:35
Mamasoboliha
Рет қаралды 11 МЛН
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 12 МЛН
Binary Tree Algorithms for Technical Interviews - Full Course
1:48:53
freeCodeCamp.org
Рет қаралды 704 М.
Rat in a Maze Problem I | Problem of the Day | GeeksForGeeks
19:00
Top 10 Javascript Algorithms to Prepare for Coding Interviews
1:52:53
freeCodeCamp.org
Рет қаралды 66 М.
Interview Experience of Publicis Sapient | Java interview Live !!
2:15:01
Recursion in Programming - Full Course
1:51:36
freeCodeCamp.org
Рет қаралды 937 М.
Pointers in C for Absolute Beginners - Full Course
2:04:29
freeCodeCamp.org
Рет қаралды 216 М.
Form a palindrome | Problem of the Day | GeeksForGeeks
17:46