# Archive for May 2021

Problem Statement Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Example 1 Input: intervals = [[1,3],[6,9]], newInterval = [2,5] Output: [[1,5],[6,9]] Example 2 Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval . . . Read more

Problem Statement Given an array of non-negative integers , you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you are able to reach the last index. Example 1 Input: nums = [2,3,1,1,4] Output: . . . Read more

Problem Statement Given the head of a linked list, rotate the list to the right by places. Example 1: Input: head = [1,2,3,4,5], k = 2 Output: [4,5,1,2,3] Example 2: Input: head = [0,1,2], k = 4 Output: [2,0,1] Solution # Definition for singly-linked list. # class ListNode: # def . . . Read more

Problem Statement Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. Example 2: Input: nums = [1] Output: 1 Example . . . Read more

Problem Statement The gray code is a binary numeral system where two successive values differ in only one bit. Given an integer n representing the total number of bits in the code, return any sequence of gray code. A gray code sequence must begin with 0. Example 1 Input: n . . . Read more

Problem Statement Given an array of non-negative integers , you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of jumps. You can assume . . . Read more