0% found this document useful (0 votes)
36 views

Arrays Questions

Arrays Questions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
36 views

Arrays Questions

Arrays Questions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
Question 1: Example 1 Input: Output: Example 2: Input: Output: Example 3: Input: Output: Constraints: ARRAYS - ASSigniment Given an integer array nums, return true if any value appears at least twice in the array, and retum false if every element is distinct. nums = [1, 2,3, 1] true nums = [1, 2,3, 4] false nums =[1, 1, 1,3,3,4,3,2,4,2] true 1 <= nums..lengtth <= 10° “10? ‘=nums [i] <= 10? Question 2: Example 1 Input: Output: Example 2: Input: Output: ‘There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly rotated at an unknown, pivot index k (1 <= k < nums.length) such that the resulting array is [nums{k], nums{k+1], .... nums[n-1], nums{o], nums{t), .., nums{k-1]] (indexed). For example, [01,245.67] might be rotated at_—pivot__ index 3 and become [4,5,6,7,0,1,2) Given the array nums after the possible rotation and an integer target, return the index of target ifit is in nums, or -1 if itis not in nums. You must write an algorithm with O(log n) runtime complexity nums = [4, 5, 6,7, 0, 1, 2], target = 0 4 nums = [4, §,6,7, 0,1, 2], target =3 Example 3: Input: Output: Constraints COLLEGE nums = [1], target = 0 1 <= nums. lenglth <= 5000 -10* <= nums [i] <= 10 All values of nums are unique. nums is an ascending array that is possibly rotated. -10* <= target <= 10* Question 3: Example 1 Input: Output: Explanation: Buy on day 2 (pric Example 2: Input: Output You are given an array prices where pricesl is the price of a given stock on the i day, Return the maxim profit you an achieve from this transaction. If you cannot achieve any profit, féturh 0. prices =[7. 1, 5,3, 6,4] 5 1) and sell on day 5 (price = 6), profit = 6-1 = 5. Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sel Prices = [7,6,4,3, 0 Explanation: _In this case, no transactions are done and the max profit = 0. Constraints: 1 <= prices length <= 10° 0 <= prices [i] <= APNA COLLEGE Question 4: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. 3 2 1 0 Example 1: Input: height = (0,1, 0,2, 1,0, 1,3,2,1,2, 1] Output: 6 Explanation: The abow is represented by array (0.1.0.2. f rain water (blue section) are bei Example 2: Input: height = [4)2,0, 3, 2/5} Output: Constraints: . n== height . length . Teen

You might also like