• 61. Rotate List

    Medium Given the head of a linked list, rotate the list to the right by k 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] Constraints: Complexity Code Continue reading

  • 59. Spiral Matrix II

    Medium Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order. Example 1: Input: n = 3 Output: [[1,2,3],[8,9,4],[7,6,5]] Example 2: Input: n = 1 Output: [[1]] Constraints: Continue reading

  • 1572. Matrix Diagonal Sum

    Easy Given a square matrix mat, return the sum of the matrix diagonals. Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal. Example 1: Input: mat = [[1,2,3],   [4,5,6],   [7,8,9]] Output: 25 Explanation: Diagonals sum: 1 +… Continue reading

  • 1456. Maximum Number of Vowels in a Substring of Given Length

    1456. Maximum Number of Vowels in a Substring of Given Length Medium Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’. Example 1: Input: s = “abciiidef”, k = 3 Output: 3 Explanation: The substring “iii” contains 3 vowel letters. Example 2: Input: s… Continue reading

  • 1822. Sign of the Product of an Array

    Easy There is a function signFunc(x) that returns: You are given an integer array nums. Let product be the product of all values in the array nums. Return signFunc(product). Example 1: Input: nums = [-1,-2,-3,-4,3,2,1] Output: 1 Explanation: The product of all values in the array is 144, and signFunc(144) = 1 Example 2: Input: nums = [1,5,0,2,-3] Output: 0 Explanation: The… Continue reading

  • 1491. Average Salary Excluding the Minimum and Maximum Salary

    Easy You are given an array of unique integers salary where salary[i] is the salary of the ith employee. Return the average salary of employees excluding the minimum and maximum salary. Answers within 10-5 of the actual answer will be accepted. Example 1: Input: salary = [4000,3000,1000,2000] Output: 2500.00000 Explanation: Minimum salary and maximum salary are 1000 and 4000 respectively. Average salary excluding minimum and maximum… Continue reading

  • 55. Jump Game

    Medium You are given an integer array nums. You are initially positioned at the array’s first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last index, or false otherwise. Example 1: Input: nums = [2,3,1,1,4] Output: true Explanation: Jump 1 step from index 0 to 1, then… Continue reading

  • 54. Spiral Matrix

    Medium Given an m x n matrix, return all elements of the matrix in spiral order. Example 1: Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,3,6,9,8,7,4,5] Example 2: Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] Output: [1,2,3,4,8,12,11,10,9,5,6,7] Constraints: Approach We’re given 2D Matrix to return 1D array by traversing in spiral. The solution relies on a simple basis of traverse in the direction and squeezing… Continue reading

  • 2336. Smallest Number in Infinite Set

    Medium You have a set which contains all positive integers [1, 2, 3, 4, 5, …]. Implement the SmallestInfiniteSet class: Example 1: Input [“SmallestInfiniteSet”, “addBack”, “popSmallest”, “popSmallest”, “popSmallest”, “addBack”, “popSmallest”, “popSmallest”, “popSmallest”] [[], [2], [], [], [], [1], [], [], []] Output Explanation SmallestInfiniteSet smallestInfiniteSet = new SmallestInfiniteSet(); smallestInfiniteSet.addBack(2); // 2 is already in the set, so no… Continue reading

  • 1046. Last Stone Weight

    Easy You are given an array of integers stones where stones[i] is the weight of the ith stone. We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weights x and y with x <= y. The result of this smash is: At the end of the game, there is at most… Continue reading

About Me

I write code, build apps, share ideas, and make bad jokes. I am currently focusing on SaaS products, especially in AI.

Newsletter