DSA_Worksheet icon indicating copy to clipboard operation
DSA_Worksheet copied to clipboard

Search in Rotated Sorted Array

Open Nikita06211 opened this issue 1 year ago • 2 comments

Write Code in Only One Language (CPP, C, Java, Python)

Give File Name : Search_Rotated_SortedArray.cpp ✅ In respective language folder

📑 DESCRIPTION

Search in Rotated Sorted Array

Difficulty

Problem Statement: This code defines a function searchInRotatedArray that takes a rotated sorted array (nums) and a target value. It uses binary search to find the index of the target in the array or returns -1 if the target is not found. The main function provides an example of using this function with a rotated array and a target value.

Note: If any

Input Format:

Size of the Rotated Sorted Array:

The user is prompted to enter the size of the rotated sorted array.
Elements of the Rotated Sorted Array:

The user is prompted to enter each element of the rotated sorted array one by one.
Target Element to Search:

The user is prompted to enter the target element that needs to be searched in the array.

Output Format:

Element [target] found at index [index] 
OR
Element [target] not found in the array

Example

Example

Sample Input 1

Enter the size of the rotated sorted array: 7
Enter the elements of the rotated sorted array: 4 5 6 7 0 1 2
Enter the target element to search: 0

Sample Output 1

Element 0 found at index 4

Constraints

The time complexity of the binary search algorithm used in this code is O(log N), where N is the size of the rotated sorted array. The space complexity is O(1) since the algorithm uses only a constant amount of extra space.

Link of Problem If Copied from Some Site

Nikita06211 avatar Oct 21 '23 06:10 Nikita06211

hey @Nikita06211 can you assign this issue for me ? I like to solve this issue please!

yashashwini16 avatar Oct 21 '23 06:10 yashashwini16

please assign this issue to me

Somil-Shukla avatar Oct 21 '23 08:10 Somil-Shukla