Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e.,[0,1,2,4,5,6,7]might become[4,5,6,7,0,1,2]). You are given a target value to search. If found in the array return its index, otherwise return-1. You may assume no duplicate exists in the array. You...
Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: "(()"Output: 2Explanation: The longest valid parentheses substring is"()"Example 2:Input: ")()())"Output: 4Explanation: The longest valid parentheses s...
Implement next permutation, which rearranges numbers into thelexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as thelowest possible order (ie, sorted in ascending order). The replacement must be in-place and use only constant extra me...
You are given a string, s, and a list of words, words, that are all ofthe same length. Find all starting indices of substring(s) in s thatis a concatenation of each word in words exactly once and without anyintervening characters.Example 1: Input: s = "barfoothefoobarman", words = ["foo","bar"] O...
Given two integers dividend and divisor, divide two integers withoutusing multiplication, division and mod operator.Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero. Example 1: Input: dividend = 10, divisor = 3 Output: 3 Example 2: Input: di...
Implement strStr().Return the index of the first occurrence of needle in haystack, or -1if needle is not part of haystack. Example 1: Input: haystack = "hello", needle = "ll" Output: 2 Example 2: Input: haystack = "aaaaa", needle = "bba" Output: -1 Clarification: What should we return when needle...
Given an array nums and a value val, remove all instances of thatvalue in-place and return the new length. Do not allocate extra space for another array, you must do this bymodifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you ...
Given a sorted array nums, remove the duplicates in-place such thateach element appear only once and return the new length. Do not allocate extra space for another array, you must do this bymodifying the input array in-place with O(1) extra memory. Example 1: Given nums = [1,1,2], Your function s...
Given a linked list, reverse the nodes of a linked list k at a timeand return its modified list.k is a positive integer and is less than or equal to the length of thelinked list. If the number of nodes is not a multiple of k thenleft-out nodes in the end should remain as it is. Example: Given thi...
Given a linked list, swap every two adjacent nodes and return itshead.You may not modify the values in the list's nodes, only nodes itselfmay be changed. Example: Given 1->2->3->4, you should return the list as 2->1->4->3.