Posts with tag 'array'

Remove Duplicate Numbers

less than 1 minute read

Given a list of integers nums, remove numbers that appear multiple times in the list, while maintaining order of the appearance in the original list.

Longest Sublist with K Distinct Numbers

1 minute read

Given an integer k and a list of integers nums, return the length of the longest sublist that contains at most k distinct integers.

Profitable Job Matching

1 minute read

You are given lists of integers people, jobs, profits. Each person i in people have people[i] amount of strength, and performing job j requires jobs[j] amoun...

Sum of Three Numbers Less than Target

1 minute read

Given a list of integers nums and an integer target, return the number of triples i < j < k that exist such that nums[i] + nums[j] + nums[k] < target.

Maximum Sum Removing K Numbers From Ends

1 minute read

You are given a list of integers nums and integer k. Return the maximum sum of elements that you can remove given that you must pop exactly k times, where ea...

Longest Sublist of 1s After K Sets

less than 1 minute read

You are given a list of integers nums containing 1s and 0s and an integer k. Given that you can set at most k 0s to 1s, return the length of the longest subl...

Longest Consecutive Sequence

1 minute read

Given an unsorted array of integers nums, find the length of the longest sequence of consecutive elements.

Sort by Permutation

less than 1 minute read

Given a list of strings lst and a list of integers p, reorder lst so that every lst[i] gets placed to p[i].

Dividing Station

1 minute read

Given a list of distinct positive integers nums, find the largest subset such that every pair of elements in the subset (i, j) satisfies either i % j = 0 or ...

Diagonal Sort

less than 1 minute read

Given a two-dimensional integer matrix, sort each of the diagonals descending from left to right in ascending order.

Rotate a Box Under Gravity

1 minute read

You are given a two-dimensional list of strings matrix. Each element in matrix contains one of the following:

Permute List to Make Largest Range Sum

1 minute read

You are given a list of integers nums and a two-dimensional list of integers ranges. Each element in ranges contains [i, j], meaning to sum the numbers in nu...

List Partitioning with Inequality Relation

less than 1 minute read

Given a list of integers nums, we want to split the list into two non-empty sublists a and b such that every element in a is less than or equal to every elem...

Maximum Unique Sublist Sum

less than 1 minute read

You are given a list of non-negative integers nums. Return the maximum sum of a sublist in nums containing only unique values.

Next Integer Permutation

less than 1 minute read

Given an integer n, return the next bigger permutation of its digits.

Sum Pairs to Target

1 minute read

You are given a list of integers nums and an integer target. In one operation we can remove any two numbers in nums if the pair sums to target. Return the ma...

Eat Bananas in K Hours

1 minute read

You are given a list of integers piles and an integer k. piles[i] represents the number of bananas on pile i. On each hour, you can choose any pile and eat r...

Submajority Vote

less than 1 minute read

You are given a list of integers nums where each number represents a vote to a candidate.

XOR Range Queries

1 minute read

You are given a list of integers nums and a two-dimensional list of integers queries. Each element in queries contains [i, j] and asks what is the value of n...

K Distinct Window

less than 1 minute read

Given a list of integers nums and an integer k, return a list of count of distinct numbers in each window of size k.

Longest Bitonic Subsequence

1 minute read

A sequence is called bitonic if it’s strictly increasing and then strictly decreasing. A sequence that is only strictly increasing is bitonic. Also, a sequen...

Matrix Search

less than 1 minute read

Given a two-dimensional integer matrix, where every row and column is sorted in ascending order, find the kth (0-indexed) smallest number.

Matrix Search Sequel

less than 1 minute read

Given a two-dimensional integer matrix, where every row and column is sorted in ascending order, return whether an integer target exists in the matrix.

Steady Speed

1 minute read

You are given a list of integers positions representing the position of a car at equally spaced intervals of time. Return the length of the longest sublist w...

Spiral Matrix

less than 1 minute read

Given a 2-d array matrix, return elements in spiral order starting from matrix[0][0].

Smallest Intersecting Element

less than 1 minute read

You are given a two-dimensional list of integers matrix where each row is sorted in ascending order. Return the smallest number that exists in every row. If ...

Find the Largest Number in a Rotated List

1 minute read

You are given a list of unique integers nums that is sorted in ascending order and is rotated at some pivot point. Find the maximum number in the rotated list.

Largest and Smallest Difference

less than 1 minute read

Given a list of integers nums and an integer k, choose elements from nums to create a list of length k such that the difference between the largest integer i...

Packing Boxes

1 minute read

Given a list of integers nums, pack consecutive elements of the same value into sublists.

Merging K Sorted Lists

less than 1 minute read

Given a list of sorted lists of integers, merge them into one large sorted list.

Binary Matrix Leftmost One

1 minute read

You are given a two-dimensional list of integers matrix which contains 1s and 0s. Given that each row is sorted in ascending order with 0s coming before 1s, ...

Valid N Queens

1 minute read

The n queens puzzle asks to place n queens on an n×n chessboard so that no two queens are attacking each other.

Three Player Coin Game

1 minute read

You are given a list of non-negative integers piles where each piles[i] represents the number of coins on pile i. In each move, you can do the following unti...

Bubble Swap

1 minute read

Given two lists of integers lst0 and lst1, each of length n and where each value is unique to its array and between 0 to n - 1, return the minimum number of ...

Wolves of Wall Street

less than 1 minute read

Given a list of integers prices representing the stock prices of a company in chronological order, return the maximum profit you could have made from buying ...

Wolf of Wall Street

1 minute read

Given a list of integers prices representing the stock prices of a company in chronological order, return the maximum profit you could have made from buying ...

Unidirectional Word Search

less than 1 minute read

Given a two-dimensional matrix of characters board and a string target, return whether the target can be found in the matrix by going left-to-right, or up-to...

Transpose of a Matrix

less than 1 minute read

Given an integer square (n by n) matrix, return its transpose. A transpose of a matrix switches the row and column indices. That is, for every r and c, matri...

Toeplitz Matrix

less than 1 minute read

Given a two-dimensional matrix of integers matrix, determine whether it’s a Toeplitz matrix. A Toeplitz is one where every diagonal descending from left to r...

Task Hare

1 minute read

You are given a list of integers tasks and another list of integers people. The integer tasks[i] represents the amount of strength required to perform the it...

Swap Consecutive Index Pairs

less than 1 minute read

Given a list of integers nums, swap each consecutive even indexes with each other, and swap each consecutive odd indexes with each other.

Sum of Two Numbers

1 minute read

Given a list of numbers nums and a number k, return whether any two elements from the list add up to k. You may not use the same element twice.

Sum of Two Numbers with Sorted List

1 minute read

Given a list of integers nums sorted in ascending order and an integer k, return whether any two elements from the list add up to k. You may not use the same...

Sum of Two Numbers Less Than Target

less than 1 minute read

Given a list of integers nums and an integer target, return the sum of the largest pair of numbers in nums whose sum is less than target. You can assume that...

Sum of Three Numbers

less than 1 minute read

Given a list of integers nums and an integer k, determine if there are three distinct elements in the list that add up to k.

Square of a List

less than 1 minute read

Given a list of integers sorted in ascending order nums, square the elements and give the output in sorted order.

Shortest Sublist With Max Frequency

1 minute read

You are given a list of integers nums. Let k be the frequency of a most frequent number in nums. Return the length of a shortest sublist such that the freque...

Shortest Sublist to Sort

1 minute read

Given a list of integers nums, return the length of the shortest sublist in nums which if sorted would make nums sorted in ascending order.

Sentence Reversal

less than 1 minute read

Given a list of strings sentence where each sentence[i] is a string with single character, reverse the order of the words in the sentence.

Rotate List Left by K

1 minute read

Write a function that rotates a list of numbers to the left by k elements. Numbers should wrap around.

Remove Last Duplicate Entries

less than 1 minute read

Given a list of integers nums, find all duplicate numbers and delete their last occurrences.

Range Update

1 minute read

You are given a list of integers nums and a two-dimensional list of integers operations. Each operation is of the following form: [L, R, X], which means that...

Rain Catcher

1 minute read

You are given a list of non-negative integers nums where each element represents the height of a hill. Suppose it will rain and all the spaces between two si...

Quadratic Application

1 minute read

You are given a list of integers nums sorted in ascending order, and integers a, b, and c. Apply the following function for each number x in nums: \(ax^2 + b...

Odd Number of Digits

less than 1 minute read

Given a list of positive integers nums, return the number of integers that have odd number of digits.

Number of Sublists With Sum of Target

less than 1 minute read

Given a list of integers nums and an integer target, return the number of sublists whose sum is equal to target.

Mixed Sorting

1 minute read

Given a list of integers nums, sort the array such that:

Minimum Initial Value for Positive Prefix Sums

less than 1 minute read

You are given a list of integers nums. Return the minimum positive value we can append to the beginning of nums such that prefix sums of the resulting list c...

Minimum Cost Sort

1 minute read

Given a list of integers nums, return the minimum cost of sorting the list in ascending or descending order. The cost is defined as the sum of absolute diffe...

Merging Two Sorted Lists

less than 1 minute read

Given two lists of integers a and b sorted in ascending order, merge them into one large sorted list.

Median Minimization

less than 1 minute read

Given a list of integers nums, split it into two lists of equal size where the absolute difference between each list’s median is as small as possible and ret...

Maximum Number by Inserting Five

less than 1 minute read

Given an integer n, return the maximum number you can make by inserting 5 anywhere in the number.

Maximize Social Distancing

1 minute read

You are given a list of integers seats containing 1s and 0s. Each element seats[i] represents a seat and is either occupied if seats[i] = 1 or empty if seats...

Max Product of Three Numbers

less than 1 minute read

Given a list of integers nums, find the largest product of three distinct elements.

Matrix Prefix Sum

less than 1 minute read

Given a two-dimensional integer matrix, return a new matrix A of the same dimensions where each element is set to A[i][j] = sum(matrix[r][c]) for all r ≤ i, ...

Longest Sign Alternating Subsequence

less than 1 minute read

Given a list of non-zero integers nums, return the length of longest subsequence that flips signs on each consecutive number.

Longest Alliteration

less than 1 minute read

Given a list of lowercase alphabet strings words, return the length of the longest contiguous sublist where all words share the same first letter.

List Partitioning

less than 1 minute read

Given a list of strings strs, containing the strings "red", "green" and "blue", partition the list so that the red come before green, which come before blue.

List Min Replacement

less than 1 minute read

Given a list of integers nums, replace every nums[i] with the smallest integer left of i. Replace nums[0] with 0.

Lexicographically Largest Mountain List

1 minute read

You are given three positive integers n, lower, and upper. You want to create a list of length n that is strictly increasing and then strictly decreasing and...

Leaderboard

less than 1 minute read

You are given a list of integers nums, representing the number of chess matches each person has won. Return a relative ranking (0-indexed) of each person. If...

Largest Sum After K Negations

1 minute read

You are given a list of integers nums and an integer k. Consider an operation where you pick an element in nums and negate it. Given that you must make exact...

Kth Smallest Element

less than 1 minute read

Given a list of unsorted integers nums, and an integer k, return the kth (0-indexed) smallest element in the list.

K Prefix

1 minute read

Given a list of integers nums and an integer k, return the maximum possible i where nums[0] + nums[1] + ... + nums[i] ≤ k. Return -1 if no valid i exists.

K Numbers Greater Than or Equal to K

less than 1 minute read

You are given a list of non-negative integers nums. If there are exactly k numbers in nums that are greater than or equal to k, return k. Otherwise, return -1.

Insertion Index in Sorted List

1 minute read

Given a list of integers nums, sorted in ascending order, and a number target, return the index where target should be inserted to keep nums sorted. If targe...

Index with Equal Left and Right Sums

1 minute read

Given a list of integer nums, return the earliest index i such that the sum of the numbers left of i is equal to the sum of numbers right of i. If there’s no...

In-Place Move Zeros to End of List

less than 1 minute read

Given a list of integers nums, put all the zeros to the back of the list by modifying the list in-place. The relative ordering of other elements should stay ...

Hoppable

1 minute read

Given an integer list nums where each number represents the maximum number of hops you can make, determine whether you can reach to the last index starting a...

Fixed Point

less than 1 minute read

Given a list of unique integers nums sorted in ascending order, return the minimum i such that nums[i] == i. If there’s no solution, return -1.

First Fit Room

1 minute read

You are given a list of integers rooms and an integer target. Return the first integer in rooms that’s target or larger. If there is no solution, return -1.

Equivalent Pairs

less than 1 minute read

You are given a list of integers nums. Return the number of pairs i < j such that nums[i] = nums[j].

Detect the Only Duplicate in a List

less than 1 minute read

You are given a list nums of length n + 1 picked from the range 1, 2, ..., n. By the pigeonhole principle, there must be a duplicate. Find and return it. The...

Consecutive Ones

less than 1 minute read

You are given a list of integers nums which contains at least one 1. Return whether all the 1s appear consecutively.

Complete an Arithmetic Sequence

less than 1 minute read

You are given a list of integers nums that used to be an arithmetic sequence. Given that a number was removed, and that the number was not the first or the l...

Column Sort

less than 1 minute read

Given a two-dimensional integer matrix, sort each of the columns in ascending order.

Buying Cars

less than 1 minute read

Given a list of integers prices representing prices of cars for sale, and a budget k, return the maximum number of cars you can buy.

Arithmetic Sequences

less than 1 minute read

Given a list of integers nums, return the number of contiguous arithmetic sequences of length ≥ 3.

Arithmetic Sequence Permutation

1 minute read

Given a list of integers nums, return whether you can rearrange the order of nums such that the difference between every consecutive two numbers is the same.

Add One to List

less than 1 minute read

You are given a list of integers nums, representing a decimal number and nums[i] is between [0, 9].

123 Number Flip

less than 1 minute read

You are given an integer n consisting of digits 1, 2, and 3 and you can flip one digit to a 3. Return the maximum number you can make.

Back to top ↑