Binary-Search-3

Problem1

Pow(x,n) (https://leetcode.com/problems/powx-n/)

Implement pow(x, n), which calculates x raised to the power n (xn).

Example 1:

Input: 2.00000, 10 Output: 1024.00000 Example 2:

Input: 2.10000, 3 Output: 9.26100 Example 3:

Input: 2.00000, -2 Output: 0.25000 Explanation: 2-2 = 1/22 = 1/4 = 0.25 Note:

-100.0 < x < 100.0 n is a 32-bit signed integer, within the range [−231, 231 − 1]

Problem2

Find K Closest Elements (https://leetcode.com/problems/find-k-closest-elements/)

Given a sorted array, two integers k and x, find the k closest elements to x in the array. The result should also be sorted in ascending order. If there is a tie, the smaller elements are always preferred.

Example 1: Input: [1,2,3,4,5], k=4, x=3 Output: [1,2,3,4] Example 2: Input: [1,2,3,4,5], k=4, x=-1 Output: [1,2,3,4] Note: The value k is positive and will always be smaller than the length of the sorted array. Length of the given array is positive and will not exceed 104 Absolute value of elements in the array and x will not exceed 104

Problem 3

https://leetcode.com/discuss/interview-question/318918/amazon-online-assessment

Problem4

Longest Duplicate Substring (https://leetcode.com/problems/longest-duplicate-substring/)

Given a string S, consider all duplicated substrings: (contiguous) substrings of S that occur 2 or more times. (The occurrences may overlap.)

Return any duplicated substring that has the longest possible length. (If S does not have a duplicated substring, the answer is "".)

Example 1:

Input: "banana" Output: "ana" Example 2:

Input: "abcd" Output: ""

Note:

2 <= S.length <= 10^5 S consists of lowercase English letters.