This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void anagramSort(String[] s){ | |
if(s==null) return; | |
Hashtable<String, LinkedList<String>> hTable=new Hashtable<String, LinkedList<String>>() | |
for(String temp: s){ | |
String key=sortChar(s); | |
if(!hTable.contains(key)){ | |
hTable.put(key, new Linkedlist<String>()); | |
} | |
LinkedList temp=hTable.get(key) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int findNuminRotatedArray(int[] arr,int l, int r, int findNum){ | |
int mid=(l+r)/2; | |
if(arr[mid]==finNum) return mid; | |
if(l>r){ | |
return -1 | |
} | |
if(arr[l]<arr[mid]){ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int binarySearch(String[] s, int start, int end, String target){ | |
mid=(stat+edn); | |
if(s[mid].equals(target)) return mid; | |
if(s[mid]!=null){ | |
if(target>s[mid]) return binarySearch(s, mid+1, end, target); | |
else return binarySearch(s, start, mid, target); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given a linked list, swap every two adjacent nodes and return its head. | |
For example, | |
Given 1->2->3->4, you should return the list as 2->1->4->3. | |
Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed. | |
/** | |
* Definition for singly-linked list. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. | |
If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is. | |
You may not alter the values in the nodes, only nodes itself may be changed. | |
Only constant memory is allowed. | |
For example, | |
Given this linked list: 1->2->3->4->5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Divide two integers without using multiplication, division and mod operator. | |
"Time complexity: [(log(dividend/divisor)](not sure)" | |
public class Solution { | |
public int divide(int dividend, int divisor) { | |
if (divisor==0){ | |
// throw new InvalidInputException("Divisor can not be 0"); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given a sorted array of integers, find the starting and ending position of a given target value. | |
Your algorithm's runtime complexity must be in the order of O(log n). | |
If the target is not found in the array, return [-1, -1]. | |
For example, | |
Given [5, 7, 7, 8, 8, 10] and target value 8, | |
return [3, 4]. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implement next permutation, which rearranges numbers into the lexicographically | |
next greater permutation of numbers.If such arrangement is not possible, it must | |
rearrange it as the lowest possible order (ie, sorted in ascending order). | |
The replacement must be in-place, do not allocate extra memory. | |
Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column. | |
1,2,3 → 1,3,2 | |
3,2,1 → 1,2,3 | |
1,1,5 → 1,5,1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given a sorted array and a target value, return the index if the target is found. If not, | |
return the index where it would be if it were inserted in order. | |
You may assume no duplicates in the array. | |
Here are few examples. | |
[1,3,5,6], 5 → 2 | |
[1,3,5,6], 2 → 1 | |
[1,3,5,6], 7 → 4 | |
[1,3,5,6], 0 → 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The count-and-say sequence is the sequence of integers beginning as follows: | |
1, 11, 21, 1211, 111221, ... | |
1 is read off as "one 1" or 11. | |
11 is read off as "two 1s" or 21. | |
21 is read off as "one 2, then one 1" or 1211. | |
Given an integer n, generate the nth sequence. | |
Note: The sequence of integers will be represented as a string. |