Accenture
Accenture
Starting with any positive integer, replace the number by the sum
of the squares of its digits.
Repeat the process until the number equals 1 (where it will stay),
or it loops endlessly in a cycle which does not include 1.
Those numbers for which this process ends in 1 are happy.
Example 1:
Input: n = 19
Output: true
Explanation:
12 + 92 = 82
82 + 22 = 68
62 + 82 = 100
12 + 02 + 02 = 1
Example 2:
Input: n = 2
Output: false
Constraints:
Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs,
then you turn off every second bulb.
On the third round, you toggle every third bulb (turning on if it's off or
turning off if it's on). For the i round, you toggle every i bulb. For
th
Example 1:
Input: n = 3
Output: 1
Explanation: At first, the three bulbs are [off, off, off].
After the first round, the three bulbs are [on, on, on].
After the second round, the three bulbs are [on, off, on].
After the third round, the three bulbs are [on, off, off].
So you should return 1 because there is only one bulb is on.
Example 2:
Input: n = 0
Output: 0
Example 3:
Input: n = 1
Output: 1
Constraints:
Two Sum
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.
Example 1:
Example 2:
Example 3:
Constraints:
Climbing Stairs
You are climbing a staircase. It takes n steps to reach the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways
can you climb to the top?
Example 1:
Input: n = 2
Output: 2
Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
Example 2:
Input: n = 3
Output: 3
Explanation: There are three ways to climb to the top.
1. 1 step + 1 step + 1 step
2. 1 step + 2 steps
3. 2 steps + 1 step
Constraints:
1 <= n <= 45
Palindrome Number
Given an integer x, return true if x is a palindrome, and false otherwise.
Example 1:
Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.
Example 2:
Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a
palindrome.
Example 3:
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Constraints:
Rotate Array
Given an integer array nums, rotate the array to the right by k steps,
where k is non-negative.
Example 1:
Example 2:
Constraints:
Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
Example 1:
Input: s = "III"
Output: 3
Explanation: III = 3.
Example 2:
Input: s = "LVIII"
Output: 58
Explanation: L = 50, V= 5, III = 3.
Example 3:
Input: s = "MCMXCIV"
Output: 1994
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
Constraints:
Maximum Subarray
Given an integer array nums, find the subarray with the largest sum, and
return its sum.
Example 1:
Example 2:
Example 3:
Constraints:
Pick any nums[i] and delete it to earn nums[i] points. Afterwards, you
must delete every element equal to nums[i] - 1 and every element
equal to nums[i] + 1.
Example 1:
Example 2:
Edit Distance
Given two strings word1 and word2, return the minimum number of
operations required to convert word1 to word2.
Insert a character
Delete a character
Replace a character
Example 1:
Example 2:
Constraints:
Constraints:
has piles[i] bananas. The guards have gone and will come back
in h hours.
Return the minimum integer k such that she can eat all the bananas
within h hours.
Example 1:
Example 2:
Example 3:
Constraints:
Example 1:
Example 2:
Example 3:
Constraints: