Chitresh-code / DSA_Worksheet

Worksheet posting DSA problems every day for GNIOT Students to solve and create PR's.
MIT License
17 stars 34 forks source link

Search in Rotated Sorted Array #64

Open Nikita06211 opened 10 months ago

Nikita06211 commented 10 months ago

❗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

yashashwini16 commented 10 months ago

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

Somil-Shukla commented 10 months ago

please assign this issue to me