medium

[Leetcode 334] Increasing Triplet Subsequence

Question Leetcode 334: Increasing Triplet Subsequence Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array. Formally the function should: Return true if there exists i, j, k such that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false. Note: Your algorithm should run in O(n) time complexity and O(1) space complexity.

[Leetcode 370] Range Addition

Question Leetcode 370: Range Addition Assume you have an array of length n initialized with all 0’s and are given k update operations. Each operation is represented as a triplet: [startIndex, endIndex, inc] which increments each element of subarray A[startIndex ... endIndex] (startIndex and endIndex inclusive) with inc. Return the modified array after all k operations were executed. Note: You must return the copy of the given head as a reference to the cloned list.

[Leetcode 768/769] Max Chunks To Make Sorted

Question 1 Leetcode 769: Max Chunks To Make Sorted II Given an array arr of integers (not necessarily distinct), we split the array into some number of “chunks” (partitions), and individually sort each chunk. After concatenating them, the result equals the sorted array. What is the most number of chunks we could have made? Note: arr will have length in range [1, 2000]. arr[i] will be an integer in range [0, 10**8].

[Leetcode 523] Continuous Subarray Sum

Question Leetcode 523: Continuous Subarray Sum Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to a multiple of k, that is, sums up to n*k where n is also an integer. Note: The length of the array won’t exceed 10,000. You may assume the sum of all the numbers is in the range of a signed 32-bit integer.

[Leetcode 138]: Copy List with Random Pointer

Question Leetcode 138: Copy List with Random Pointer A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. Note: You must return the copy of the given head as a reference to the cloned list. Node definition: class Node: def __init__(self, val, next, random): self.val = val self.