Author: devangini123
Problem Statement: Given a string s, find the length of the longest substring without duplicate characters. Examples: Example 1: Input: s = “abcabcbb” Output: 3 Explanation: The answer is “abc”, with the length of 3. Example 2: Input: s = “bbbbb” Output: 1 Explanation: The answer is “b”, with the length of 1. Example 3: Input: s = “pwwkew” Output: 3 Explanation: The answer is “wke”, with the length of 3. Notice that the answer must be a substring, “pwke” is a subsequence and not a substring. Constraints: 0
Problem Statement: 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. Examples: Example 1: Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Example 2: Input: height = [4,2,0,3,2,5] Output:9 Constraints: n == height.length 1 =0; i–){ maxR[i] = (arr[i] > maxR[i+1]) ? arr[i] : maxR[i+1]; } int ans = 0; for(int i=0; i 0) ? waterTrapped : 0; } return ans;…
Problem Statement: Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Examples: Example 1: Input:haystack = “sadbutsad”, needle = “sad” Output:0 Explanation: “sad” occurs at index 0 and 6.The first occurrence is at index 0, so we return 0. Example 2: Input:haystack = “leetcode”, needle = “leeto” Output:-1 Explanation: “leeto” did not occur in “leetcode”, so we return -1. Constraints: 1
Problem Statement: Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. Examples: Example 1: Input:nums = [-1,0,1,2,-1,-4] Output:[[-1,-1,2],[-1,0,1]] Explanation: nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0. nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0. nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0. The distinct triplets are [-1,0,1] and [-1,-1,2]. Notice that…
Problem Statement: You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not slant the container. Examples: Example 1: Input:height = [1,8,6,2,5,4,8,3,7] Output:49 Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can…
Problem Statement: Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null. For example, the following two linked lists begin to intersect at node c1 The test cases are generated such that there are no cycles anywhere in the entire linked structure. Note that the linked lists must retain their original structure after the function returns. Custom Judge: The inputs to the judge are given as follows (your program is not given these inputs): intersectVal – The value of…
Problem Statement: Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Examples: Example 1: Input:haystack = “sadbutsad”, needle = “sad” Output:0 Explanation: “sad” occurs at index 0 and 6.The first occurrence is at index 0, so we return 0. Example 2: Input:haystack = “leetcode”, needle = “leeto” Output:-1 Explanation: “leeto” did not occur in “leetcode”, so we return -1. Constraints: 1
Problem Statement: Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., “ace” is a subsequence of “abcde” while “aec” is not). Examples: Example 1: Input: s = “abc”, t = “ahbgdc” Output: true Example 2: Input: s = “axc”, t = “ahbgdc” Output: false Constraints: 0
Problem Statement: Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 target: j -= 1 elif sum < target: i += 1 else: return [i + 1, j + 1] return [] class Solution { public int[] twoSum(int[] numbers, int target) { int i = 0; int j = numbers.length - 1; while(i < j) { int sum = numbers[i] + numbers[j]; if(sum > target) { –j; } else if(sum < target)…
🌙 Problem Statement: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Examples: Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. Example 2: Input: nums = [3,2,4], target = 6 Output: [1,2] Example 3: Input: nums = [3,3], target = 6 Output: [0,1] Constraints:…
Contact Us
Subscribe to Stay Updated
Stay ahead in the world of tech with our exclusive newsletter! Subscribe now for regular updates on the latest trends, valuable coding resources, and tips to boost your frontend development skills.
