Practice (Basic)

back to index  |  new

Find the number of solutions to the equation $7\sin x + 2\cos^2 x = 5$ for $0\le x < 2\pi$.


Find the point on the circle $(x − 5)^2 + (y − 4)^2 = 4$ which is closest to the circle $(x − 1)^2 + (y − 1)^2 = 1$.


Let function $f(x)$ satisfy:  $$\int^1_0 3f (x) dx +\int^2_1 2f (x) dx = 7$$

and $$\int^2_0 f (x) dx + \int^2_1 f (x) dx = 1$$

Find the value of $$\int^2_0 f (x) dx$$


Find the area of the region bounded by the curve $y=\sqrt{x}$, the line line $y=x-2$, and the $x-$ axis.


Let $a$, $b$, $c$ and $d$ be real numbers. Find the relation of these four numbers such that the two curves $y=ax^2+c$ and $y=bx^2 + d$ have exactly two points of intersections.

Find the value of $c$ such that two parabolas $y=x^2+c$ and $y^2=x$ touch at a single point.


Explain why we cannot apply the cut-the-rope technique to count the non-negative integer solutions to the equation $$x_1 + x_2 + \cdots + x_k = n$$

For example, can we allow two cuts in the same interval thus to model one of the $x_i$ is zero?


Randomly draw a card twice with replacement from $1$ to $10$, inclusive. What is the probability that the product of these two cards is a multiple of $7$?


How many even $4$- digit integers are there whose digits are distinct?


Derive the permutation formula $P_n^n=n\times (n-1)\times\cdots\times 2\times 1$ using the recursion method.


Find the minimal value of $4^m + 4^n$ if $m+n=3$.


Show that the $(k+1)$ leading digits of the number $\underbrace{333\cdots 3}_{k}4^2$ are all $1$s. Here $k$ is any positive integer.


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.


A numeric array of length $N$ is given. We need to design a function that finds all positive numbers in the array that have their opposites in it as well. Describe approaches for solving optimal worst case and optimal average case performance, respectively.


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.

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]4

Output: $9$


A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers. Given a string s, return true if it is a palindrome, or false otherwise. (Note that s consists only of printable ASCII characters.)

Example 1:

Input: s = "A man, a plan, a canal: Panama"

Output: true

Explanation: "amanaplanacanalpanama" is a palindrome.

Example 2:

Input: s = "race a car"

Output: false

Explanation: "raceacar" is not a palindrome.

Example 3:

Input: s = " "

Output: true

Explanation: s is an empty string "" after removing non-alphanumeric characters.

Since an empty string reads the same forward and backward, it is a palindrome.


Given a string s (containing only lower case English words), return true if the s can be palindrome after deleting at most one character from it.

Example 1:

Input: s = "aba"

Output: true

Example 2:

Input: s = "abca"

Output: true

Explanation: You could delete the character 'c'.

Example 3:

Input: s = "abc"

Output: false


Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list. (Follow up: Could you do it in one pass?)

Example 1:

Input: head = [1,2,3,4,5], left = 2, right = 4

Output: [1,4,3,2,5]

Reasoning: 2 - 4 is [2,3,4]. We want to reverse it in place [4,3,2]. We do not modify the linked list elsewhere, giving us the final [1,4,3,2,5]

Example 2:

Input: head = [5], left = 1, right = 1

Output: [5]

 


Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

An input string is valid if:

  • Open brackets must be closed by the same type of brackets.
  • Open brackets must be closed in the correct order.
  • Every close bracket has a corresponding open bracket of the same type.

Example 1:

Input: s = "()"

Output: true

Example 2:

Input: s = "()[]{}"

Output: true

Example 3:

Input: s = "(]"

Output: false


Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string. Formally, a parentheses string is valid if and only if:

  • It is the empty string, contains only lowercase characters, or
  • It can be written as AB (A concatenated with B), where A and B are valid strings, or
  • It can be written as (A), where A is a valid string.

Example 1:

Input: s = "lee(t(c)o)de)"

Output: "lee(t(c)o)de"

Explanation: "lee(t(co)de)" , "lee(t(c)ode)" would also be accepted.

Example 2:

Input: s = "a)b(c)d"

Output: "ab(c)d"

Example 3:

Input: s = "))(("

Output: ""

Explanation: An empty string is also valid.