L1 Part2
L1 Part2
Example 1:
Input: nums = [3,1,4,2]
Output: 1
Example 2:
Input: nums = [10,20,5,30]
Output: 5
2) Reverse an Array
Given an array of integers, return the reversed array.
Example 1:
Input: nums = [1,2,3]
Output: [3,2,1]
Example 2:
Input: nums = [10,5,7]
Output: [7,5,10]
Example 1:
Input: nums = [1,2,3,4,3], target = 3
Output: 2
Example 2:
Input: nums = [5,6,7], target = 8
Output: -1
Example 1:
Input: nums = [1,2,3,4]
Output: True
Example 2:
Input: nums = [1,3,2,4]
Output: False
Example 1:
Input: s = 'hello'
Output: 5
Example 2:
Input: s = 'python'
Output: 6
Example 1:
Input: s = 'hello'
Output: 2
Example 2:
Input: s = 'world'
Output: 1
Example 1:
Input: s = 'racecar'
Output: True
Example 2:
Input: s = 'hello'
Output: False
Example 1:
Input: s = 'hello'
Output: 'HELLO'
Example 2:
Input: s = 'Python'
Output: 'PYTHON'
9) Binary Search
Given a sorted array and a target, return the index of the target if found, otherwise return -
1.
Example 1:
Input: nums = [1,3,5,7], target = 5
Output: 2
Example 2:
Input: nums = [2,4,6,8], target = 3
Output: -1
Example 1:
Input: nums = [1,4,3,7]
Output: 7
Example 2:
Input: nums = [10,20,30]
Output: 30
Example 1:
Input: nums = [1,2,3,4]
Output: 2
Example 2:
Input: nums = [10,15,20,25]
Output: 2
Example 1:
Input: num = 7
Output: True
Example 2:
Input: num = 10
Output: False
Example 1:
Input: num = 5
Output: 120
Example 2:
Input: num = 3
Output: 6
Example 1:
Input: n = 5
Output: 5
Example 2:
Input: n = 7
Output: 13
Example 1:
Input: a = 12, b = 18
Output: 6
Example 2:
Input: a = 7, b = 13
Output: 1
Example 1:
Input: a = 4, b = 5
Output: 20
Example 2:
Input: a = 6, b = 8
Output: 24
Example 1:
Input: num = 123
Output: 6
Example 2:
Input: num = 456
Output: 15
Example 1:
Input: nums = [1,2,2,3,4,4]
Output: [1,2,3,4]
Example 2:
Input: nums = [5,5,6,7,7]
Output: [5,6,7]
Example 1:
Input: nums1 = [1,3,5], nums2 = [2,4,6]
Output: [1,2,3,4,5,6]
Example 2:
Input: nums1 = [10,20], nums2 = [15,25]
Output: [10,15,20,25]
Example 1:
Input: nums = [1,5,3,9,7]
Output: 7
Example 2:
Input: nums = [10,20,30,40]
Output: 30