Next Greater Element 2

Problem Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums. The next greater number of a number x is the first greater number to its traversing-order next in the array, which means you could search circularly to find its next greater number. If it doesn’t exist, return -1 for this number. ...

Backspace String Compare Problem

Problem Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character. Note that after backspacing an empty text, the text will continue empty. Examples Example 1: Input: s = "ab#c", t = "ad#c" Output: true Explanation: Both s and t become "ac". ...

Valid Perfect Square Problem

Problem Given a positive integer num, write a function which returns True if num is a perfect square else False. Follow up: Do not use any built-in library function such as sqrt. Examples Example 1: Input: num = 16 Output: true Example 2: Input: num = 14 Output: false ...

Nested List Weight Sum 2

Problem You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. The depth of an integer is the number of lists that it is inside of. For example, the nested list [1 ,[2,2],[ [3],2],1 ] has each integer’s value set to its depth. Let maxDepth be the maximum depth of any integer. ...

01 Matrix Problem

Problem Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1. Examples Example 1: $$ \begin{bmatrix} 0 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 0 \end{bmatrix} $$ Input: mat = [ [0,0,0],[0,1,0],[0,0,0] ] Output: [ [0,0,0],[0,1,0],[0,0,0] ] ...

Android Unlock Patterns Problem

Problem Given an Android 3x3 key lock screen and two integers m and n, where 1 ≤ m ≤ n ≤ 9, count the total number of unlock patterns of the Android lock screen, which consist of minimum of m keys and maximum n keys. Rules for a valid pattern: Each pattern must connect at least m keys and at most n keys. All the keys must be distinct. If the line connecting two consecutive keys in the pattern passes through any other keys, the other keys must have previously selected in the pattern. No jumps through non selected key is allowed. The order of keys used matters. ...

Intersection of Two Arrays 2 - Duplicates allowed

Problem Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order. Examples Example 1: Input: nums1 = [1,2,2,1], nums2 = [2,2] Output: [2,2] ...

Intersection of Two Arrays 1 - Unique Elements

Problem Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order. Examples Example 1: Input: nums1 = [1, 2, 2, 1], nums2 = [2, 2] Output: [2] ...

Longest Substring with At Most K Distinct Characters Problem

Problem Given a string S, find the length of the longest substring T that contains at most k distinct characters. Examples Example 1: Input: S = "eceba" and k = 3 Output: 4 Explanation: T = "eceb" Example 2: Input: S = "WORLD" and k = 4 Output: 4 Explanation: T = "WORL" or "ORLD" ...

Nested List Weight Sum

Problem Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer, or a list – whose elements may also be integers or other lists. Examples Example 1: Input: [ [1,1],2,[1,1] ] Output: 10 Explanation: Four 1's at depth 2, one 2 at depth 1. ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy