Posts with tag 'math'

Airplane Seat Shuffling

1 minute read

You are given an integer n representing the number of seats in an airplane. The first person has lost their ticket, so they pick a random seat. Everyone else...

Count Substrings With All 1s

less than 1 minute read

You are given a string s containing "1"s and "0"s. Return the number of substrings that contain only "1"s. Mod the result by 10 ** 9 + 7.

Ugly Number

less than 1 minute read

Given an integer n, return whether its prime factors only include 2, 3 or 5.

Sum of the Digits

less than 1 minute read

Given a positive integer num, return the sum of its digits.

Sum of First N Odd Integers

less than 1 minute read

Given an integer n, return the sum of the first n positive odd integers.

Search in a Virtually Complete Binary Tree

1 minute read

Consider a complete binary tree of n nodes whose values are 1 to n. The root has value of 1, its left child is 2 and its right child is 3. In general, nodes’...

Prime Factorization

less than 1 minute read

You can write out a number as a product of prime numbers, which are its prime factors. The same prime factor may occur more than once.

Palindromic Integer

less than 1 minute read

Given a non-negative integer num, return whether it is a palindrome.

N-Rooks

1 minute read

You’ve got an integer n representing a chessboard of size n x n. Return the number of ways you can place n rooks, such that no two rooks attack each other.

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...

List Equality with Increments

less than 1 minute read

You are given a list of integers nums, and want to make the values equal. Consider an operation where you pick an integer in the list and increment every oth...

Linked List to Integer

less than 1 minute read

Given a single linked list node, representing a binary number with most significant digits first, return it as an integer.

Line Segment

less than 1 minute read

Given a list of [x, y] coordinates in a Cartesian plane, return whether the coordinates form a straight line segment.

Line of People

1 minute read

You are given integers n, a and b. You are standing in a line of n people. You don’t know which position you’re in, but you know there are at least a people ...

Integer to Base 3

less than 1 minute read

Given an integer n, return its base 3 representation as a string.

Guess the Root

less than 1 minute read

Given a non-negative integer n, find a number r such that r * r = n and round down to the nearest integer.

Greatest Common Divisor

less than 1 minute read

Given a list of positive integers nums, return the largest positive integer that divides each of the integers.

Generate Primes

less than 1 minute read

Given a number n, return a list of all prime numbers smaller than or equal to n in ascending order.

First to Count to Target

1 minute read

You are playing a game against a friend where in each round you pick a number from 1 to k to add to a shared running total that initially starts from 0. The ...

Factorial Sum

less than 1 minute read

Given a positive integer n, return whether n can be written as the sum of distinct positive factorial numbers.

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...

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...

Clock Angle

less than 1 minute read

Given a clock time with hour and integer minutes, determine the smaller angle between the hour and the minute hands and floor it to the nearest integer.

Base 3 to Integer

less than 1 minute read

Given a string s representing a number in base 3 (consisting only of 0, 1, or 2), return its decimal integer equivalent. This should be implemented directly ...

Back to top ↑