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 class MinParkingSpace { | |
| public static int minParkingSpace(int[][] slots) { | |
| //insert your code here | |
| return 0; | |
| } | |
| public static void main(String[] args) { | |
| final int[][] pairs = new int[][] { {13,16}, {9,10}, | |
| {8,12}, {6,7}, | |
| {11,14}, {3,5}, {2,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
| package chapter1; | |
| import java.util.Random; | |
| public class LinkedList { | |
| Node head; | |
| static Random random = new Random(); | |
| LinkedList(int number){ |
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
| package chapter2; | |
| public class LinkedListKthToLast { | |
| Node head; // head of list | |
| static class Node { | |
| int data; | |
| Node next; | |
| Node(int d) { | |
| data = d; |
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
| import java.util.HashMap; | |
| import java.util.Map; | |
| public class LinkedListOneWithBuffer { | |
| Node head; // head of list | |
| static class Node { | |
| int data; | |
| Node next; |
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 class Ch01Problem09 { | |
| /*String Rotation:Assumeyou have a method isSubstringwhich checks if one word is a substring | |
| of another. Given two strings, sl and s2, write code to check if s2 is a rotation of sl using only one | |
| call to isSubstring (e.g., "waterbottle" is a rotation of"erbottlewat").*/ | |
| public static void main(String[] args){ | |
| String str1 = "akshayphate"; | |
| String str2 = "phateakshat"; | |
| System.out.println(isSubstring(str1.toCharArray(), str2.toCharArray())); |
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
| package chapter1; | |
| class Ch01Problem06{ | |
| /*String Compression: Implement a method to perform basic string compression using the counts | |
| of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the | |
| "compressed" string would not become smaller than the original string, your method should return | |
| the original string. You can assume the string has only uppercase and lowercase letters (a - z).*/ | |
| public static void main(String[] args){ | |
| /*If I am replacing a continuous stream of a single character with the character itself and its occurrences |
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 class Ch01Problem05 { | |
| /*One Away : There are three types of edits that can be performed on strings: | |
| * insert, replace and remove a character. Given two strings, write a function to check if they are one edit awa | |
| * pale, ple -> true | |
| * pale, bake -> false | |
| * pale, bale -> true | |
| */ | |
| public static void main(String[] args) { | |
| String first = "akshay"; |
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
| import java.util.HashMap; | |
| import java.util.Map; | |
| public class Ch01Problem04 { | |
| /*Palindrome Permutation: Given a string write a function to check if it is permutation of a | |
| * palindrome. The palindrome does not need to be limited to just dictionary words */ | |
| public static void main(String[] args) { | |
| String str = "atco cta"; | |
| System.out.println(palindrome(str.toCharArray())); |
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 class Ch01Problem03 { | |
| /*URLify : write a method to replace all spaces in a string with "%20". you may assume that the string | |
| has sufficient space at the end to hold the additional characters, and that you are given | |
| the "true" length of the string. | |
| example INPUT : "Mr akshay phate ", 19 | |
| OUTPUT : "Mr%20akshay%20phate" | |
| */ | |
| public static void main(String[] args) { | |
| String str = "cris rafa messi "; |
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
| import java.util.HashMap; | |
| class Ch01Problem02{ | |
| //given two strings, write a method to decide if one is a permutation of the other | |
| public static void main(String[] args){ | |
| String str1 = "ankushchoubey"; | |
| String str2 = "choubeyankush"; | |
| System.out.print(permute(str1, str2)); | |
| } |
NewerOlder