Given a singly linked list, determine if it is a palindrome.
Follow up
Could you do it in O(n) time and O(1) space?
Given a singly linked list, determine if it is a palindrome.
Could you do it in O(n) time and O(1) space?
Given a collection of integers that might contain duplicates, nums, return all possible subsets.
Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets.
If nums = [1,2,2], a solution is:
[ [2], [1], [1,2,2], [2,2], [1,2], [] ]
Given a list, rotate the list to the right by k places, where k is non-negative.
Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL.
Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.
Given “egg”, “add”, return true.
Given “foo”, “bar”, return false.
Given “paper”, “title”, return true.
You may assume both s and t have the same length.
Implement atoi to convert a string to an integer.
Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.
It is intended for this problem to be specified vaguely (ie, no given input specs). You are responsible to gather all the input requirements up front.
The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.
The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.
If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.
If no valid conversion could be performed, a zero value is returned. If the correct value is out of the range of representable values, INT_MAX (2147483647) or INT_MIN (-2147483648) is returned.
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.
Given nums = [1, 2, 1, 3, 2, 5], return [3, 5].
The order of the result is not important. So in the above example, [5, 3] is also correct. Your algorithm should run in linear runtime complexity. Could you implement it using only constant space complexity?
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
Expected runtime complexity is in O(log n) and the input is sorted.
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.
Example 1: coins = [1, 2, 5], amount = 11 return 3 (11 = 5 + 5 + 1)
Example 2: coins = [2], amount = 3 return -1.
You may assume that you have an infinite number of each kind of coin.
Given a sorted integer array without duplicates, return the summary of its ranges.
For example, given [0,1,2,4,5,7], return [“0->2”,“4->5”,“7”]