Search a 2D matrix where each row and column is sorted.
Write an efficient algorithm that searches for a value target in an m x n integer matrix. Integers in each row are sorted, and the first integer of each row is greater than the last integer of the previous row.
Input: matrix = [[1,4],[2,5]], target = 20
Output: FALSE
Explanation:…
Alien Dictionary Order
Derive the alien dictionary order from a sorted list of alien words.
Input: words = ["z","x","z"]
Output: "" (Empty String)
Explanation: The letter 'z' cannot come before 'x' and then suddenly after 'x', creating a cycle and making the dictionary invalid.
Palindromes in Base-10 and Base-k
Return the first n integers that are palindromes in both base-10 and base-k.
Input: n = 2, k = 4
Output: [1, 5]
Explanation: 1 is '1' in base 4, and 5 is '11' in base 4. Both are perfect palindromes in decimal and base 4 simultaneously.
Implement the next permutation algorithm.
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such an arrangement is not possible, it must rearrange it as the lowest possible order.
Input: nums = [3,2,1]
Output: [1,2,3]
Explanation: The sequence is strictly decreasing…