Capgemini
Capgemini
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:
Example 1:
Input: s = "abc"
Output: 148
Explanation:
Lette Index in
Index in Reversed Alphabet Product
r String
'a' 26 1 26
'b' 25 2 50
'c' 24 3 72
Example 2:
Input: s = "zaza"
Output: 160
Explanation:
Lette Index in
Index in Reversed Alphabet Product
r String
'z' 1 1 1
'a' 26 2 52
'z' 1 3 3
'a' 26 4 104
The reverse degree is 1 + 52 + 3 + 104 = 160.
Constraints:
Custom Judge:
The judge will test your solution with the following code:
assert k == expectedNums.length;
for (int i = 0; i < k; i++) {
assert nums[i] == expectedNums[i];
}
Example 1:
Example 2:
Constraints:
Example 1:
Example 2:
Constraints:
You want to maximize your profit by choosing a single day to buy one
stock and choosing a different day in the future to sell that stock.
Return the maximum profit you can achieve from this transaction. If
you cannot achieve any profit, return 0.
Example 1:
Example 2:
Constraints:
Example 1:
Example 2:
Example 3:
Input: s = "a good example"
Output: "example good a"
Explanation: You need to reduce multiple spaces between two words to a single space in the reversed
string.
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:
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
Example 1:
Input: n = 2
Output: 1
Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
Example 2:
Input: n = 3
Output: 2
Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
Example 3:
Input: n = 4
Output: 3
Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.
Constraints:
0 <= n <= 30
Example 2:
Constraints:
Example 1:
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:
Input: s = "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
Example 3:
Input: s = "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
Constraints:
Valid Anagram
Given two strings s and t, return true if t is an anagram of s,
and false otherwise.
Example 1:
Output: true
Example 2:
Output: false
Constraints:
Exchange Seats
SQL Schema
Pandas Schema
Table: Seat
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| student | varchar |
+-------------+---------+
id is the primary key (unique value) column for this table.
Each row of this table indicates the name and the ID of a student.
The ID sequence always starts from 1 and increments continuously.
Write a solution to swap the seat id of every two consecutive
students. If the number of students is odd, the id of the last
student is not swapped.
Return the result table ordered by id in ascending order.
The result format is in the following example.
Example 1:
Input:
Seat table:
+----+---------+
| id | student |
+----+---------+
| 1 | Abbot |
| 2 | Doris |
| 3 | Emerson |
| 4 | Green |
| 5 | Jeames |
+----+---------+
Output:
+----+---------+
| id | student |
+----+---------+
| 1 | Doris |
| 2 | Abbot |
| 3 | Green |
| 4 | Emerson |
| 5 | Jeames |
+----+---------+
Explanation:
Note that if the number of students is odd, there is no need to change the last one's seat.
Group Anagrams
Medium
Topics
Companies
Given an array of strings strs, group the anagrams together. You can
return the answer in any order.
Example 1:
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
Explanation:
Example 2:
Output: [[""]]
Example 3:
Output: [["a"]]
Constraints:
Example 2:
Constraints:
nums1.length == m
nums2.length == n
0 <= m <= 1000
0 <= n <= 1000
1 <= m + n <= 2000
-106 <= nums1[i], nums2[i] <= 106
Example 1:
Input: a = 1, b = 1, c = 7
Output: "ccaccbcc"
Explanation: "ccbccacc" would also be a correct answer.
Example 2:
Input: a = 7, b = 1, c = 0
Output: "aabaa"
Explanation: It is the only correct answer in this case.
Constraints:
You are given two non-empty linked lists representing two non-
negative integers. The digits are stored in reverse order, and each of
their nodes contains a single digit. Add the two numbers and return the
sum as a linked list.
You may assume the two numbers do not contain any leading zero,
except the number 0 itself.
Example 1:
Input: l1 = [2,4,3], l2 = [5,6,4]
Output: [7,0,8]
Explanation: 342 + 465 = 807.
Example 2:
Example 3:
Constraints:
The number of nodes in each linked list is in the range [1, 100].
0 <= Node.val <= 9
It is guaranteed that the list represents a number that does not
have leading zeros.
Valid Palindrome
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.
Example 1:
Example 2:
Example 3:
Constraints:
Example 1:
Input: head = [1,2,3,4,5], n = 2
Output: [1,2,3,5]
Example 2:
Example 3:
Constraints:
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:
Move Zeroes
Given an integer array nums, move all 0's to the end of it while
maintaining the relative order of the non-zero elements.
Note that you must do this in-place without making a copy of the
array.
Example 1:
Example 2:
Constraints:
You want to maximize your profit by choosing a single day to buy one
stock and choosing a different day in the future to sell that stock.
Return the maximum profit you can achieve from this transaction. If
you cannot achieve any profit, return 0.
Example 1:
Example 2:
Constraints: