├── Algorithms (S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani).pdf
├── CTCI Edition 4 solutions
├── .classpath
├── .metadata
│ ├── .lock
│ ├── .mylyn
│ │ └── repositories.xml.zip
│ └── version.ini
├── .project
├── CareerCupLibrary
│ └── CareerCupLibrary
│ │ ├── AssortedMethods.java
│ │ ├── BitVector.java
│ │ ├── LinkedListNode.java
│ │ └── TreeNode.java
├── Chapter 1
│ ├── Question1_1
│ │ └── Question.java
│ ├── Question1_3
│ │ └── Question.java
│ ├── Question1_4
│ │ └── Question.java
│ ├── Question1_5
│ │ └── Question.java
│ ├── Question1_6
│ │ └── Question.java
│ ├── Question1_7
│ │ └── Question.java
│ └── Question1_8
│ │ └── Question.java
├── Chapter 10
│ ├── Question10_3
│ │ ├── Line.java
│ │ └── Question.java
│ ├── Question10_4
│ │ └── Question.java
│ ├── Question10_5
│ │ ├── Line.java
│ │ ├── Point.java
│ │ ├── Question.java
│ │ └── Square.java
│ ├── Question10_6
│ │ ├── GraphPoint.java
│ │ ├── Line.java
│ │ └── Question.java
│ └── Question10_7
│ │ └── Question.java
├── Chapter 11
│ ├── Question11_2
│ │ ├── Machine.java
│ │ ├── Person.java
│ │ └── Server.java
│ ├── Question11_3
│ │ └── Question.java
│ └── Question11_4
│ │ ├── BitSet.java
│ │ └── Question.java
├── Chapter 18
│ └── Question18_4
│ │ ├── MyThread.java
│ │ ├── Question.java
│ │ └── Resource.java
├── Chapter 19
│ ├── Question19_1
│ │ └── Question.java
│ ├── Question19_10
│ │ └── Question.java
│ ├── Question19_11
│ │ └── Question.java
│ ├── Question19_2
│ │ └── Question.java
│ ├── Question19_3
│ │ └── Question.java
│ ├── Question19_4
│ │ └── Question.java
│ ├── Question19_5
│ │ └── Question.java
│ ├── Question19_6
│ │ └── Question.java
│ ├── Question19_7
│ │ └── Question.java
│ ├── Question19_8
│ │ └── Question.java
│ └── Question19_9
│ │ └── Question.java
├── Chapter 2
│ ├── Question2_1
│ │ └── Question.java
│ ├── Question2_2
│ │ └── Question.java
│ ├── Question2_3
│ │ └── Question.java
│ ├── Question2_4
│ │ └── Question.java
│ └── Question2_5
│ │ └── Question.java
├── Chapter 20
│ ├── Question20_1
│ │ └── Question.java
│ ├── Question20_10
│ │ └── Question.java
│ ├── Question20_11
│ │ ├── Question20_10.java
│ │ └── Subsquare.java
│ ├── Question20_12
│ │ └── Question.java
│ ├── Question20_13
│ │ ├── Question.java
│ │ ├── Rectangle.java
│ │ ├── Trie.java
│ │ ├── TrieNode.java
│ │ └── WordGroup.java
│ ├── Question20_2
│ │ └── Question.java
│ ├── Question20_3
│ │ └── Question.java
│ ├── Question20_4
│ │ └── Question.java
│ ├── Question20_5
│ │ └── Question.java
│ ├── Question20_7
│ │ ├── LengthComparator.java
│ │ └── Question.java
│ ├── Question20_8
│ │ ├── Question.java
│ │ ├── SuffixTree.java
│ │ └── SuffixTreeNode.java
│ └── Question20_9
│ │ ├── MaxHeapComparator.java
│ │ ├── MinHeapComparator.java
│ │ └── Question.java
├── Chapter 3
│ ├── Question3_1
│ │ ├── Question.java
│ │ ├── QuestionB.java
│ │ └── StackNode.java
│ ├── Question3_2
│ │ ├── NodeWithMin.java
│ │ ├── Question.java
│ │ ├── StackWithMin.java
│ │ └── StackWithMin2.java
│ ├── Question3_3
│ │ ├── Node.java
│ │ ├── Question.java
│ │ ├── SetOfStacks.java
│ │ └── Stack.java
│ ├── Question3_4
│ │ ├── Question.java
│ │ └── Tower.java
│ ├── Question3_5
│ │ ├── MyQueue.java
│ │ └── Question.java
│ └── Question3_6
│ │ └── Question.java
├── Chapter 4
│ ├── Question4_1
│ │ └── Question.java
│ ├── Question4_2
│ │ ├── Graph.java
│ │ ├── Node.java
│ │ └── Question.java
│ ├── Question4_3
│ │ └── Question.java
│ ├── Question4_4
│ │ └── Question.java
│ ├── Question4_5
│ │ └── Question.java
│ ├── Question4_6
│ │ └── Question.java
│ ├── Question4_7
│ │ └── Question.java
│ └── Question4_8
│ │ └── Question.java
├── Chapter 5
│ ├── Question5_1
│ │ └── Question.java
│ ├── Question5_2
│ │ └── Question.java
│ ├── Question5_3
│ │ └── Question.java
│ ├── Question5_5
│ │ └── Question.java
│ ├── Question5_6
│ │ └── Question.java
│ ├── Question5_7.zip
│ └── Question5_7
│ │ ├── BitInteger.java
│ │ └── Question.java
├── Chapter 7
│ ├── Question7_1
│ │ ├── BlackJackCard.java
│ │ └── Card.java
│ ├── Question7_2
│ │ ├── Call.java
│ │ ├── CallHandler.java
│ │ ├── Employee.java
│ │ ├── Fresher.java
│ │ ├── ProductManager.java
│ │ └── TechLead.java
│ ├── Question7_3
│ │ ├── CD.java
│ │ ├── CDPlayer.java
│ │ ├── JukeBox.java
│ │ ├── Playlist.java
│ │ ├── Song.java
│ │ ├── TrackSelector.java
│ │ └── User.java
│ ├── Question7_4
│ │ ├── ChessFormat.java
│ │ ├── ChessPieceBase.java
│ │ ├── ChessPieceTurn.java
│ │ ├── ComputerPlayer.java
│ │ ├── GameManager.java
│ │ ├── HumanPlayer.java
│ │ ├── King.java
│ │ ├── PlayerBase.java
│ │ ├── Position.java
│ │ ├── PositionBackTracker.java
│ │ ├── PositionEstimator.java
│ │ ├── PositionPotentialValue.java
│ │ └── Queen.java
│ ├── Question7_5
│ │ ├── Book.java
│ │ ├── OnlineReaderSystem.java
│ │ └── User.java
│ └── Question7_8
│ │ └── Question.java
├── Chapter 8
│ ├── Question8_1
│ │ └── Question.java
│ ├── Question8_2
│ │ └── Question.java
│ ├── Question8_3
│ │ └── Question.java
│ ├── Question8_4
│ │ └── Question.java
│ ├── Question8_5
│ │ └── Question.java
│ ├── Question8_6
│ │ └── Question.java
│ ├── Question8_7
│ │ └── Question.java
│ └── Question8_8
│ │ └── Question.java
├── Chapter 9
│ ├── Question9_1
│ │ └── Question.java
│ ├── Question9_2
│ │ ├── AnagramComparator.java
│ │ └── Question.java
│ ├── Question9_3
│ │ └── Question.java
│ ├── Question9_5
│ │ └── Question.java
│ ├── Question9_6
│ │ └── Question9_6.java
│ └── Question9_7
│ │ ├── HtWt.java
│ │ └── Question.java
├── bin
│ ├── CareerCupLibrary
│ │ ├── AssortedMethods.class
│ │ ├── BitVector.class
│ │ ├── LinkedListNode.class
│ │ └── TreeNode.class
│ ├── Question10_3
│ │ ├── Line.class
│ │ └── Question.class
│ ├── Question10_4
│ │ └── Question.class
│ ├── Question10_5
│ │ ├── Line.class
│ │ ├── Point.class
│ │ ├── Question.class
│ │ └── Square.class
│ ├── Question10_6
│ │ ├── GraphPoint.class
│ │ ├── Line.class
│ │ └── Question.class
│ ├── Question10_7
│ │ └── Question.class
│ ├── Question11_2
│ │ ├── Machine.class
│ │ ├── Person.class
│ │ └── Server.class
│ ├── Question11_3
│ │ └── Question.class
│ ├── Question11_4
│ │ ├── BitSet.class
│ │ └── Question.class
│ ├── Question18_4
│ │ ├── MyThread.class
│ │ ├── Question.class
│ │ └── Resource.class
│ ├── Question19_1
│ │ └── Question.class
│ ├── Question19_10
│ │ └── Question.class
│ ├── Question19_11
│ │ └── Question.class
│ ├── Question19_2
│ │ ├── Question$Check.class
│ │ ├── Question$Piece.class
│ │ └── Question.class
│ ├── Question19_3
│ │ └── Question.class
│ ├── Question19_4
│ │ └── Question.class
│ ├── Question19_5
│ │ ├── Question$Result.class
│ │ └── Question.class
│ ├── Question19_6
│ │ └── Question.class
│ ├── Question19_7
│ │ └── Question.class
│ ├── Question19_8
│ │ └── Question.class
│ ├── Question19_9
│ │ └── Question.class
│ ├── Question1_1
│ │ └── Question.class
│ ├── Question1_3
│ │ └── Question.class
│ ├── Question1_4
│ │ └── Question.class
│ ├── Question1_5
│ │ └── Question.class
│ ├── Question1_6
│ │ └── Question.class
│ ├── Question1_7
│ │ └── Question.class
│ ├── Question1_8
│ │ └── Question.class
│ ├── Question20_1
│ │ └── Question.class
│ ├── Question20_10
│ │ └── Question.class
│ ├── Question20_11
│ │ ├── Question20_10.class
│ │ └── Subsquare.class
│ ├── Question20_12
│ │ └── Question.class
│ ├── Question20_13
│ │ ├── Question.class
│ │ ├── Rectangle.class
│ │ ├── Trie.class
│ │ ├── TrieNode.class
│ │ └── WordGroup.class
│ ├── Question20_2
│ │ └── Question.class
│ ├── Question20_3
│ │ └── Question.class
│ ├── Question20_4
│ │ └── Question.class
│ ├── Question20_5
│ │ └── Question.class
│ ├── Question20_7
│ │ ├── LengthComparator.class
│ │ └── Question.class
│ ├── Question20_8
│ │ ├── Question.class
│ │ ├── SuffixTree.class
│ │ └── SuffixTreeNode.class
│ ├── Question20_9
│ │ ├── MaxHeapComparator.class
│ │ ├── MinHeapComparator.class
│ │ └── Question.class
│ ├── Question2_1
│ │ └── Question.class
│ ├── Question2_2
│ │ └── Question.class
│ ├── Question2_3
│ │ └── Question.class
│ ├── Question2_4
│ │ └── Question.class
│ ├── Question2_5
│ │ └── Question.class
│ ├── Question3_1
│ │ ├── Question.class
│ │ ├── QuestionB.class
│ │ └── StackNode.class
│ ├── Question3_2
│ │ ├── NodeWithMin.class
│ │ ├── Question.class
│ │ ├── StackWithMin.class
│ │ └── StackWithMin2.class
│ ├── Question3_3
│ │ ├── Node.class
│ │ ├── Question.class
│ │ ├── SetOfStacks.class
│ │ └── Stack.class
│ ├── Question3_4
│ │ ├── Question.class
│ │ └── Tower.class
│ ├── Question3_5
│ │ ├── MyQueue.class
│ │ └── Question.class
│ ├── Question3_6
│ │ └── Question.class
│ ├── Question4_1
│ │ └── Question.class
│ ├── Question4_2
│ │ ├── Graph.class
│ │ ├── Node.class
│ │ ├── Question$State.class
│ │ └── Question.class
│ ├── Question4_3
│ │ └── Question.class
│ ├── Question4_4
│ │ └── Question.class
│ ├── Question4_5
│ │ └── Question.class
│ ├── Question4_6
│ │ └── Question.class
│ ├── Question4_7
│ │ └── Question.class
│ ├── Question4_8
│ │ └── Question.class
│ ├── Question5_1
│ │ └── Question.class
│ ├── Question5_2
│ │ └── Question.class
│ ├── Question5_3
│ │ └── Question.class
│ ├── Question5_5
│ │ └── Question.class
│ ├── Question5_6
│ │ └── Question.class
│ ├── Question5_7
│ │ ├── BitInteger.class
│ │ └── Question.class
│ ├── Question7_1
│ │ ├── BlackJackCard.class
│ │ ├── Card$Suit.class
│ │ └── Card.class
│ ├── Question7_2
│ │ ├── Call.class
│ │ ├── CallHandler.class
│ │ ├── Employee.class
│ │ ├── Fresher.class
│ │ ├── ProductManager.class
│ │ └── TechLead.class
│ ├── Question7_3
│ │ ├── CD.class
│ │ ├── CDPlayer.class
│ │ ├── JukeBox.class
│ │ ├── Playlist.class
│ │ ├── Song.class
│ │ ├── TrackSelector.class
│ │ └── User.class
│ ├── Question7_4
│ │ ├── ChessFormat.class
│ │ ├── ChessPieceBase.class
│ │ ├── ChessPieceTurn.class
│ │ ├── ComputerPlayer.class
│ │ ├── GameManager.class
│ │ ├── HumanPlayer.class
│ │ ├── King.class
│ │ ├── PlayerBase.class
│ │ ├── Position.class
│ │ ├── PositionBackTracker.class
│ │ ├── PositionEstimator.class
│ │ ├── PositionPotentialValue.class
│ │ └── Queen.class
│ ├── Question7_5
│ │ ├── Book.class
│ │ ├── OnlineReaderSystem.class
│ │ └── User.class
│ ├── Question7_8
│ │ └── Question.class
│ ├── Question8_1
│ │ └── Question.class
│ ├── Question8_2
│ │ └── Question.class
│ ├── Question8_3
│ │ └── Question.class
│ ├── Question8_4
│ │ └── Question.class
│ ├── Question8_5
│ │ └── Question.class
│ ├── Question8_6
│ │ ├── Question$Color.class
│ │ └── Question.class
│ ├── Question8_7
│ │ └── Question.class
│ ├── Question8_8
│ │ └── Question.class
│ ├── Question9_1
│ │ └── Question.class
│ ├── Question9_2
│ │ ├── AnagramComparator.class
│ │ └── Question.class
│ ├── Question9_3
│ │ └── Question.class
│ ├── Question9_5
│ │ └── Question.class
│ ├── Question9_6
│ │ └── Question9_6.class
│ └── Question9_7
│ │ ├── HtWt.class
│ │ └── Question.class
└── input_file_q11_4.txt
├── Companies Qts & Topic wise Qts
├── Amazon - Last 1 year based on Frequency.pdf
├── Amazon - Last 2 year based on Frequency.pdf
├── Amazon - Last 6 months based on Frequency.pdf
├── AmazonQts.txt
├── Backtracking - LeetCode(Based on Frequency).pdf
├── Backtracking pattern - Questions & Soln (Subsets, Permutations, Combination Sum, Palindrome Partitioning).pdf
├── Benchling Coding Test.txt
├── Binary Search Tree - LeetCode(Based on Frequency).pdf
├── Blackrock.txt
├── Blackrock_Full_time_questions.txt
├── Breadth-first Search - LeetCode(Based on Frequency).pdf
├── Cisco - All time.pdf
├── Cisco - last 1 year.pdf
├── Cisco - last 2 year.pdf
├── Cisco - last 6 months.pdf
├── Depth-first Search - LeetCode(Based on Frequency).pdf
├── Dynamic Programming - LeetCode(Based on Frequency).pdf
├── Fidessa.txt
├── Google - Last 1 year(based on Frequency).pdf
├── Google - Last 6 months(based on Frequency).pdf
├── Google Full Time Questions
│ ├── Google - Questions and Solutions.txt
│ ├── Google Q1.PNG
│ └── Google Q2.PNG
├── Google Prep Q &A.docx
├── Heap - LeetCode(Based on Frequency).pdf
├── IPSY - Full Time SE Role - Test Questions and Solutions.txt
├── IPSY Software Engg First Round Q & A.txt
├── Linked List - LeetCode(Based on Frequency).pdf
├── Next Captial Test Questions.txt
├── Oracle - LeetCode(all time).pdf
├── Oracle - LeetCode(last 1 year).pdf
├── Oracle - LeetCode(last 6 months).pdf
├── Queue - LeetCode(Based on Frequency).pdf
├── Salesforce.txt
├── Stack - LeetCode(Based on Frequency).pdf
└── Topological Sort - LeetCode.pdf
├── Cormen_Algorithms_3rd.pdf
├── Leetcode Problems and Solutions
├── 1. Two Sum.java
├── 10. Regular Expression Matching.java
├── 100. Same Tree.java
├── 101. Symmetric Tree.java
├── 1013. Partition Array Into Three Parts With Equal Sum.java
├── 102. Binary Tree Level Order Traversal.java
├── 103. Binary Tree Zigzag Level Order Traversal.java
├── 104. Maximum Depth of Binary Tree.java
├── 107. Binary Tree Level Order Traversal II.java
├── 108. Convert Sorted Array to Binary Search Tree.java
├── 109. Convert Sorted List to Binary Search Tree.java
├── 11. Container With Most Water.java
├── 110. Balanced Binary Tree.java
├── 111. Minimum Depth of Binary Tree.java
├── 112. Path Sum.java
├── 113. Path Sum II.java
├── 114. Flatten Binary Tree to Linked List.java
├── 116. Populating Next Right Pointers in Each Node.java
├── 117. Populating Next Right Pointers in Each Node II.java
├── 12. Integer to Roman.java
├── 120. Triangle.java
├── 121. Best Time to Buy and Sell Stock.java
├── 122. Best Time to Buy and Sell Stock II.java
├── 125. Valid Palindrome.java
├── 127. Word Ladder.java
├── 129. Sum Root to Leaf Numbers.java
├── 13. Roman to Integer.java
├── 130. Surrounded Regions.java
├── 131. Palindrome Partitioning.java
├── 133. Clone Graph.java
├── 136. Single Number.java
├── 138. Copy List with Random Pointer.java
├── 139. Word Break.java
├── 14. Longest Common Prefix.java
├── 141. Linked List Cycle.java
├── 142. Linked List Cycle II.java
├── 143. Reorder List.java
├── 144. Binary Tree Preorder Traversal.java
├── 145. Binary Tree Postorder Traversal.java
├── 146. LRU Cache.java
├── 147. Insertion Sort List.java
├── 148. Sort List.java
├── 15. 3Sum.java
├── 151. Reverse Words in a String.java
├── 152. Maximum Product Subarray.java
├── 153. Find Minimum in Rotated Sorted Array.java
├── 155. Min Stack.java
├── 16. 3Sum Closest.java
├── 160. Intersection of Two Linked Lists.java
├── 162. Find Peak Element.java
├── 167. Two Sum II - Input array is sorted.java
├── 169. Majority Element.java
├── 17. Letter Combinations of a Phone Number.java
├── 173. Binary Search Tree Iterator.java
├── 175. Combine Two Tables.java
├── 179. Largest Number.java
├── 18. 4Sum.java
├── 187. Repeated DNA Sequences.java
├── 189. Rotate Array.java
├── 19. Remove Nth Node From End of List.java
├── 191. Number of 1 Bits.java
├── 193. Valid Phone Numbers.java
├── 198. House Robber.java
├── 199. Binary Tree Right Side View.java
├── 2. Add Two Numbers.java
├── 20. Valid Parentheses.java
├── 200. Number of Islands.java
├── 202. Happy Number.java
├── 203. Remove Linked List Elements.java
├── 205. Isomorphic Strings.java
├── 206. Reverse Linked List.java
├── 207. Course Schedule.java
├── 208. Implement Trie (Prefix Tree).java
├── 209. Minimum Size Subarray Sum.java
├── 21. Merge Two Sorted Lists.java
├── 210. Course Schedule II.java
├── 213. House Robber II.java
├── 215. Kth Largest Element in an Array.java
├── 217. Contains Duplicate.java
├── 219. Contains Duplicate II.java
├── 22. Generate Parentheses.java
├── 220. Contains Duplicate III.java
├── 221. Maximal Square.java
├── 222. Count Complete Tree Nodes.java
├── 225. Implement Stack using Queues.java
├── 226. Invert Binary Tree.java
├── 227. Basic Calculator II.java
├── 228. Summary Ranges.java
├── 23. Merge k Sorted Lists.java
├── 230. Kth Smallest Element in a BST.java
├── 231. Power of Two.java
├── 232. Implement Queue using Stacks.java
├── 234. Palindrome Linked List.java
├── 235. Lowest Common Ancestor of a Binary Search Tree.java
├── 236. Lowest Common Ancestor of a Binary Tree.java
├── 237. Delete Node in a Linked List.java
├── 238. Product of Array Except Self.java
├── 24. Swap Nodes in Pairs.java
├── 240. Search a 2D Matrix II.java
├── 242. Valid Anagram.java
├── 25. Reverse Nodes in k-Group.java
├── 257. Binary Tree Paths.java
├── 258. Add Digits.java
├── 26. Remove Duplicates from Sorted Array.java
├── 264. Ugly Number II.java
├── 268. Missing Number.java
├── 27. Remove Element.java
├── 278. First Bad Version.java
├── 279. Perfect Squares.java
├── 28. Implement strStr().java
├── 283. Move Zeroes.java
├── 287. Find the Duplicate Number.java
├── 289. Game of Life.java
├── 29. Divide Two Integers.java
├── 295. Find Median from Data Stream.java
├── 297. Serialize and Deserialize Binary Tree.java
├── 299. Bulls and Cows.java
├── 3. Longest Substring Without Repeating Characters.java
├── 300. Longest Increasing Subsequence.java
├── 301. Remove Invalid Parentheses.java
├── 303. Range Sum Query - Immutable.java
├── 304. Range Sum Query 2D - Immutable.java
├── 31. Next Permutation.java
├── 310. Minimum Height Trees.java
├── 322. Coin Change.java
├── 328. Odd Even Linked List.java
├── 329. Longest Increasing Path in a Matrix.java
├── 33. Search in Rotated Sorted Array.java
├── 336. Palindrome Pairs.java
├── 337. House Robber III.java
├── 338. Counting Bits.java
├── 34. Find First and Last Position of Element in Sorted Array.java
├── 341. Flatten Nested List Iterator.java
├── 344. Reverse String.java
├── 345. Reverse Vowels of a String.java
├── 347. Top K Frequent Elements.java
├── 349. Intersection of Two Arrays.java
├── 35. Search Insert Position.java
├── 350. Intersection of Two Arrays II.java
├── 355. Design Twitter.java
├── 36. Valid Sudoku.java
├── 367. Valid Perfect Square.java
├── 37. Sudoku Solver.java
├── 371. Sum of Two Integers.java
├── 373. Find K Pairs with Smallest Sums.java
├── 374. Guess Number Higher or Lower.java
├── 378. Kth Smallest Element in a Sorted Matrix.java
├── 38. Count and Say.java
├── 380. Insert Delete GetRandom O(1).java
├── 383. Ransom Note.java
├── 384. Shuffle an Array.java
├── 385. Mini Parser.java
├── 387. First Unique Character in a String.java
├── 389. Find the Difference.java
├── 39. Combination Sum.java
├── 392. Is Subsequence.java
├── 394. Decode String.java
├── 395. Longest Substring with At Least K Repeating Characters.java
├── 40. Combination Sum II.java
├── 402. Remove K Digits.java
├── 412. Fizz Buzz.java
├── 414. Third Maximum Number.java
├── 415. Add Strings.java
├── 417. Pacific Atlantic Water Flow.java
├── 42. Trapping Rain Water.java
├── 429. N-ary Tree Level Order Traversal.java
├── 43. Multiply Strings.java
├── 430. Flatten a Multilevel Doubly Linked List.java
├── 433. Minimum Genetic Mutation.java
├── 434. Number of Segments in a String.java
├── 438. Find All Anagrams in a String.java
├── 443. String Compression.java
├── 445. Add Two Numbers II.java
├── 448. Find All Numbers Disappeared in an Array.java
├── 45. Jump Game II.java
├── 451. Sort Characters By Frequency.java
├── 456. 132 Pattern.java
├── 459. Repeated Substring Pattern.java
├── 46. Permutations.java
├── 460. LFU Cache.java
├── 461. Hamming Distance.java
├── 463. Island Perimeter.java
├── 468. Validate IP Address.java
├── 47. Permutations II.java
├── 473. Matchsticks to Square.java
├── 476. Number Complement.java
├── 48. Rotate Image.java
├── 482. License Key Formatting.java
├── 485. Max Consecutive Ones.java
├── 49. Group Anagrams.java
├── 494. Target Sum.java
├── 5. Longest Palindromic Substring.java
├── 50. Pow(x, n).java
├── 500. Keyboard Row.java
├── 509. Fibonacci Number.java
├── 513. Find Bottom Left Tree Value.java
├── 515. Find Largest Value in Each Tree Row.java
├── 518. Coin Change 2.java
├── 520. Detect Capital.java
├── 524. Longest Word in Dictionary through Deleting.java
├── 529. Minesweeper.java
├── 53. Maximum Subarray.java
├── 530. Minimum Absolute Difference in BST.java
├── 532. K-diff Pairs in an Array.java
├── 535. Encode and Decode TinyURL.java
├── 54. Spiral Matrix.java
├── 542. 01 Matrix.java
├── 543. Diameter of Binary Tree.java
├── 55. Jump Game.java
├── 559. Maximum Depth of N-ary Tree.java
├── 56. Merge Intervals.java
├── 560. Subarray Sum Equals K.java
├── 561. Array Partition I.java
├── 563. Binary Tree Tilt.java
├── 566. Reshape the Matrix.java
├── 572. Subtree of Another Tree.java
├── 58. Length of Last Word.java
├── 581. Shortest Unsorted Continuous Subarray.java
├── 583. Delete Operation for Two Strings.java
├── 59. Spiral Matrix II.java
├── 599. Minimum Index Sum of Two Lists.java
├── 6. ZigZag Conversion.java
├── 60. Permutation Sequence.java
├── 605. Can Place Flowers.java
├── 61. Rotate List.java
├── 617. Merge Two Binary Trees.java
├── 62. Unique Paths.java
├── 621. Task Scheduler.java
├── 628. Maximum Product of Three Numbers.java
├── 63. Unique Paths II.java
├── 637. Average of Levels in Binary Tree.java
├── 64. Minimum Path Sum.java
├── 647. Palindromic Substrings.java
├── 648. Replace Words.java
├── 654. Maximum Binary Tree.java
├── 657. Robot Return to Origin.java
├── 658. Find K Closest Elements.java
├── 66. Plus One.java
├── 67. Add Binary.java
├── 671. Second Minimum Node In a Binary Tree.java
├── 675. Cut Off Trees for Golf Event.java
├── 69. Sqrt(x).java
├── 690. Employee Importance.java
├── 692. Top K Frequent Words.java
├── 695. Max Area of Island.java
├── 698. Partition to K Equal Sum Subsets.java
├── 7. Reverse Integer.java
├── 70. Climbing Stairs.java
├── 703. Kth Largest Element in a Stream.java
├── 704. Binary Search.java
├── 705. Design HashSet.java
├── 707. Design Linked List.java
├── 709. To Lower Case.java
├── 71. Simplify Path.java
├── 712. Minimum ASCII Delete Sum for Two Strings.java
├── 719. Find K-th Smallest Pair Distance.java
├── 72. Edit Distance.java
├── 725. Split Linked List in Parts.java
├── 729. My Calendar I.java
├── 73. Set Matrix Zeroes.java
├── 731. My Calendar II.java
├── 733. Flood Fill.java
├── 739. Daily Temperatures.java
├── 74. Search a 2D Matrix.java
├── 743. Network Delay Time.java
├── 746. Min Cost Climbing Stairs.java
├── 75. Sort Colors.java
├── 752. Open the Lock.java
├── 767. Reorganize String.java
├── 77. Combinations.java
├── 771. Jewels and Stones.java
├── 78. Subsets.java
├── 787. Cheapest Flights Within K Stops.java
├── 79. Word Search.java
├── 791. Custom Sort String.java
├── 792. Number of Matching Subsequences.java
├── 794. Valid Tic-Tac-Toe State.java
├── 8. String to Integer (atoi).java
├── 80. Remove Duplicates from Sorted Array II.java
├── 804. Unique Morse Code Words.java
├── 81. Search in Rotated Sorted Array II.java
├── 814. Binary Tree Pruning.java
├── 815. Bus Routes.java
├── 817. Linked List Components.java
├── 819. Most Common Word.java
├── 82. Remove Duplicates from Sorted List II.java
├── 822. Card Flipping Game.java
├── 825. Friends Of Appropriate Ages.java
├── 83. Remove Duplicates from Sorted List.java
├── 832. Flipping an Image.java
├── 833. Find And Replace in String.java
├── 84. Largest Rectangle in Histogram.java
├── 842. Split Array into Fibonacci Sequence.java
├── 844. Backspace String Compare.java
├── 852. Peak Index in a Mountain Array.java
├── 86. Partition List.java
├── 863. All Nodes Distance K in Binary Tree.java
├── 872. Leaf-Similar Trees.java
├── 876. Middle of the Linked List.java
├── 88. Merge Sorted Array.java
├── 880. Decoded String at Index.java
├── 89. Gray Code.java
├── 897. Increasing Order Search Tree.java
├── 9. Palindrome Number.java
├── 90. Subsets II.java
├── 904. Fruit Into Baskets.java
├── 905. Sort Array By Parity.java
├── 909. Snakes and Ladders.java
├── 91. Decode Ways.java
├── 911. Online Election.java
├── 92. Reverse Linked List II.java
├── 929. Unique Email Addresses.java
├── 93. Restore IP Addresses.java
├── 934. Shortest Bridge.java
├── 94. Binary Tree Inorder Traversal.java
├── 946. Validate Stack Sequences.java
├── 96. Unique Binary Search Trees.java
├── 973. K Closest Points to Origin.java
├── 976. Largest Perimeter Triangle.java
├── 98. Validate Binary Search Tree.java
└── 994. Rotting Oranges.java
├── Misc Notes
├── Cracking the Coding Interview 4th Edition.pdf
├── Cracking the coding Interview 6th Edition.pdf
├── Java Questions.docx
├── Java Time Complexity Gist.txt
├── Leetcode Solutions Version 1.pdf
├── Leetcode Solutions Version 2.pdf
├── Leetcode Solutions Version 3.pdf
├── OO File System.doc
├── OOP Design Ques of the Battleship Game.pdf
├── Operating Systems quesitons.docx
└── Template - Substring questions.txt
├── README.md
├── The Algorithm Design Manual by Steven S. Skiena.pdf
├── competitive programming by steven & felix halim.pdf
└── the-design-and-implementation-marshall-kirk-mckusick-george-v-neville-neil(www.ebook-dl.com).pdf
/Algorithms (S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Algorithms (S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani).pdf
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/.metadata/.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/.metadata/.lock
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/.metadata/.mylyn/repositories.xml.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/.metadata/.mylyn/repositories.xml.zip
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/.metadata/version.ini:
--------------------------------------------------------------------------------
1 | org.eclipse.core.runtime=1
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Cracking the Technical Interview
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/CareerCupLibrary/CareerCupLibrary/AssortedMethods.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/CareerCupLibrary/CareerCupLibrary/AssortedMethods.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/CareerCupLibrary/CareerCupLibrary/LinkedListNode.java:
--------------------------------------------------------------------------------
1 | package CareerCupLibrary;
2 |
3 | public class LinkedListNode {
4 | public LinkedListNode next;
5 | public LinkedListNode prev;
6 | public int data;
7 | public LinkedListNode(int d, LinkedListNode n, LinkedListNode p) {
8 | data = d;
9 | setNext(n);
10 | setPrevious(p);
11 | }
12 |
13 | public void setNext(LinkedListNode n) {
14 | next = n;
15 | if (n != null && n.prev != this) {
16 | n.setPrevious(this);
17 | }
18 | }
19 |
20 | public void setPrevious(LinkedListNode p) {
21 | prev = p;
22 | if (p != null && p.next != this) {
23 | p.setNext(this);
24 | }
25 | }
26 |
27 | public String printForward() {
28 | if (next != null) {
29 | return data + "->" + next.printForward();
30 | } else {
31 | return ((Integer) data).toString();
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 1/Question1_1/Question.java:
--------------------------------------------------------------------------------
1 | package Question1_1;
2 |
3 | public class Question {
4 |
5 | public static boolean isUniqueChars(String str) {
6 | int checker = 0;
7 | for (int i = 0; i < str.length(); ++i) {
8 | int val = str.charAt(i) - 'a';
9 | if ((checker & (1 << val)) > 0) return false;
10 | checker |= (1 << val);
11 | }
12 | return true;
13 | }
14 |
15 | public static boolean isUniqueChars2(String str) {
16 | boolean[] char_set = new boolean[256];
17 | for (int i = 0; i < str.length(); i++) {
18 | int val = str.charAt(i);
19 | if (char_set[val]) return false;
20 | char_set[val] = true;
21 | }
22 | return true;
23 | }
24 |
25 | public static void main(String[] args) {
26 | String[] words = {"abcde", "hello", "apple", "kite", "padle"};
27 | for (String word : words) {
28 | System.out.println(word + ": " + isUniqueChars(word) + " " + isUniqueChars2(word));
29 | }
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 1/Question1_4/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 1/Question1_4/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 1/Question1_5/Question.java:
--------------------------------------------------------------------------------
1 | package Question1_5;
2 |
3 | import CareerCupLibrary.AssortedMethods;
4 |
5 | public class Question {
6 | // Assume string has sufficient free space at the end
7 | public static void ReplaceFun(char[] str, int length) {
8 | int spaceCount = 0, newLength, i = 0;
9 | for (i = 0; i < length; i++) {
10 | if (str[i] == ' ') {
11 | spaceCount++;
12 | }
13 | }
14 | newLength = length + spaceCount * 2;
15 | str[newLength] = '\0';
16 | for (i = length - 1; i >= 0; i--) {
17 | if (str[i] == ' ') {
18 | str[newLength - 1] = '0';
19 | str[newLength - 2] = '2';
20 | str[newLength - 3] = '%';
21 | newLength = newLength - 3;
22 | } else {
23 | str[newLength - 1] = str[i];
24 | newLength = newLength - 1;
25 | }
26 | }
27 | }
28 |
29 | public static void main(String[] args) {
30 | String str = "abc d e f";
31 | char[] arr = new char[str.length() + 3 * 2 + 1];
32 | for (int i = 0; i < str.length(); i++) {
33 | arr[i] = str.charAt(i);
34 | }
35 | ReplaceFun(arr, str.length());
36 | System.out.println(AssortedMethods.charArrayToString(arr));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 1/Question1_6/Question.java:
--------------------------------------------------------------------------------
1 | package Question1_6;
2 |
3 | import CareerCupLibrary.*;
4 |
5 | public class Question {
6 |
7 | public static void rotate(int[][] matrix, int n) {
8 | for (int layer = 0; layer < n / 2; ++layer) {
9 | int first = layer;
10 | int last = n - 1 - layer;
11 | for(int i = first; i < last; ++i) {
12 | int offset = i - first;
13 | int top = matrix[first][i]; // save top
14 |
15 | // left -> top
16 | matrix[first][i] = matrix[last-offset][first];
17 |
18 | // bottom -> left
19 | matrix[last-offset][first] = matrix[last][last - offset];
20 |
21 | // right -> bottom
22 | matrix[last][last - offset] = matrix[i][last];
23 |
24 | // top -> right
25 | matrix[i][last] = top; // right <- saved top
26 | }
27 | }
28 | }
29 |
30 | public static void main(String[] args) {
31 | int[][] matrix = AssortedMethods.randomMatrix(10, 10, 0, 9);
32 | AssortedMethods.printMatrix(matrix);
33 | rotate(matrix, 10);
34 | System.out.println();
35 | AssortedMethods.printMatrix(matrix);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 1/Question1_7/Question.java:
--------------------------------------------------------------------------------
1 | package Question1_7;
2 |
3 | import CareerCupLibrary.AssortedMethods;
4 |
5 | public class Question {
6 | public static void setZeros(int[][] matrix) {
7 | int[] row = new int[matrix.length];
8 | int[] column = new int[matrix[0].length];
9 |
10 | // Store the row and column index with value 0
11 | for (int i = 0; i < matrix.length; i++) {
12 | for (int j = 0; j < matrix[0].length;j++) {
13 | if (matrix[i][j] == 0) {
14 | row[i] = 1;
15 | column[j] = 1;
16 | }
17 | }
18 | }
19 |
20 | // Set arr[i][j] to 0 if either row i or column j has a 0
21 | for (int i = 0; i < matrix.length; i++) {
22 | for (int j = 0; j < matrix[0].length; j++) {
23 | if ((row[i] == 1 || column[j] == 1)) {
24 | matrix[i][j] = 0;
25 | }
26 | }
27 | }
28 | }
29 |
30 | public static void main(String[] args) {
31 | int M = 3;
32 | int N = 5;
33 | int[][] matrix = AssortedMethods.randomMatrix(3, 5, 0, 5);
34 | AssortedMethods.printMatrix(matrix);
35 | setZeros(matrix);
36 | System.out.println();
37 | System.out.println();
38 | AssortedMethods.printMatrix(matrix);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 1/Question1_8/Question.java:
--------------------------------------------------------------------------------
1 | package Question1_8;
2 |
3 | public class Question {
4 | public static boolean isSubstring(String big, String small) {
5 | if (big.indexOf(small) >= 0) {
6 | return true;
7 | } else {
8 | return false;
9 | }
10 | }
11 |
12 | public static boolean isRotation(String s1, String s2) {
13 | int len = s1.length();
14 | /* check that s1 and s2 are equal length and not empty */
15 | if (len == s2.length() && len > 0) {
16 | /* concatenate s1 and s1 within new buffer */
17 | String s1s1 = s1 + s1;
18 | return isSubstring(s1s1, s2);
19 | }
20 | return false;
21 | }
22 |
23 | public static void main(String[] args) {
24 | String[][] pairs = {{"apple", "pleap"}, {"waterbottle", "erbottlewat"}, {"camera", "macera"}};
25 | for (String[] pair : pairs) {
26 | String word1 = pair[0];
27 | String word2 = pair[1];
28 | boolean is_rotation = isRotation(word1, word2);
29 | System.out.println(word1 + ", " + word2 + ": " + is_rotation);
30 | }
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 10/Question10_3/Line.java:
--------------------------------------------------------------------------------
1 | package Question10_3;
2 |
3 |
4 | public class Line {
5 | static double epsilon = 0.000001;
6 | public double slope;
7 | public double yintercept;
8 |
9 | public Line(double s, double y) {
10 | slope = s;
11 | yintercept = y;
12 | }
13 |
14 | public void print() {
15 | System.out.print("y = " + slope + "x + " + yintercept);
16 | }
17 |
18 | public boolean intersect(Line line2) {
19 | return Math.abs(slope - line2.slope) > epsilon ||
20 | Math.abs(yintercept - line2.yintercept) < epsilon;
21 | }
22 | };
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 10/Question10_3/Question.java:
--------------------------------------------------------------------------------
1 | package Question10_3;
2 |
3 | public class Question {
4 | public static int randomInt(int n) {
5 | return (int) (Math.random() * n);
6 | }
7 |
8 | public static void main(String[] args) {
9 | for (int i = 0; i < 10; i++) {
10 | Line line1 = new Line(randomInt(5), randomInt(1));
11 | Line line2 = new Line(randomInt(5), randomInt(2));
12 | line1.print();
13 | System.out.print(", ");
14 | line2.print();
15 | if (line1.intersect(line2)) {
16 | System.out.println(" YES");
17 | } else {
18 | System.out.println(" NO");
19 | }
20 | }
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 10/Question10_5/Line.java:
--------------------------------------------------------------------------------
1 | package Question10_5;
2 |
3 | public class Line {
4 | public Point start;
5 | public Point end;
6 | public Line(Point start, Point end) {
7 | this.start = start;
8 | this.end = end;
9 | }
10 |
11 | public String toString() {
12 | return "Line from " + start.toString() + " to " + end.toString();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 10/Question10_5/Point.java:
--------------------------------------------------------------------------------
1 | package Question10_5;
2 |
3 | public class Point {
4 | public double x;
5 | public double y;
6 | public Point(double x, double y) {
7 | this.x = x;
8 | this.y = y;
9 | }
10 |
11 | public boolean isEqual(Point p) {
12 | return (p.x == x && p.y == y);
13 | }
14 |
15 | public String toString() {
16 | return "(" + x + ", " + y + ")";
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 10/Question10_5/Question.java:
--------------------------------------------------------------------------------
1 | package Question10_5;
2 |
3 | public class Question {
4 |
5 | public static int randomInt(int n) {
6 | return (int) (Math.random() * n);
7 | }
8 |
9 | public static void main(String[] args) {
10 | for (int i = 0; i < 10; i++) {
11 | Square s1 = new Square(randomInt(5), randomInt(5), randomInt(4) + 1);
12 | Square s2 = new Square(randomInt(5), randomInt(5), randomInt(4) + 1);
13 | System.out.println("Square: " + s1.toString());
14 | System.out.println("Square: " + s2.toString());
15 | Line line = s1.cut(s2);
16 | System.out.println(line.toString());
17 | }
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 10/Question10_5/Square.java:
--------------------------------------------------------------------------------
1 | package Question10_5;
2 |
3 | public class Square {
4 | public double left;
5 | public double top;
6 | public double bottom;
7 | public double right;
8 | public Square(double left, double top, double size) {
9 | this.left = left;
10 | this.top = top;
11 | this.bottom = top + size;
12 | this.right = left + size;
13 | }
14 |
15 | public Point middle() {
16 | return new Point((this.left + this.right)/2, (this.top + this.bottom)/2);
17 | }
18 |
19 | public Line cut(Square other) {
20 | Point middle_s = this.middle();
21 | Point middle_t = other.middle();
22 | if (middle_s == middle_t) {
23 | return new Line(new Point(left, top), new Point(right, bottom));
24 | } else {
25 | return new Line(middle_s, middle_t);
26 | }
27 | }
28 |
29 | public String toString() {
30 | return "(" + left + ", " + top + ")|(" + right + "," + bottom + ")";
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 10/Question10_6/GraphPoint.java:
--------------------------------------------------------------------------------
1 | package Question10_6;
2 |
3 | public class GraphPoint {
4 | public double x;
5 | public double y;
6 | public GraphPoint(double x1, double y1) {
7 | x = x1;
8 | y = y1;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 10/Question10_6/Line.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 10/Question10_6/Line.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 10/Question10_6/Question.java:
--------------------------------------------------------------------------------
1 | package Question10_6;
2 |
3 | import java.util.HashMap;
4 | public class Question {
5 | public static Line findBestLine(GraphPoint[] points) {
6 | Line bestLine = null;
7 | HashMap line_count =
8 | new HashMap();
9 | for (int i = 0; i < points.length; i++) {
10 | for (int j = i + 1; j < points.length; j++) {
11 | Line line = new Line(points[i], points[j]);
12 | if (!line_count.containsKey(line)) {
13 | line_count.put(line, 0);
14 | }
15 | line_count.put(line, line_count.get(line) + 1);
16 | if (bestLine == null ||
17 | line_count.get(line) > line_count.get(bestLine)) {
18 | bestLine = line;
19 | }
20 | }
21 | }
22 | return bestLine;
23 | }
24 |
25 | public static void main(String[] args) {
26 | int graph_size = 100;
27 | int n_points = 500;
28 | GraphPoint[] points = new GraphPoint[n_points];
29 | for (int i = 0; i < n_points; i++) {
30 | double x = ((double)(Math.random() * graph_size));
31 | double y = ((double)(Math.random() * graph_size));
32 | points[i] = new GraphPoint(x, y);
33 | }
34 | Line line = findBestLine(points);
35 | line.Print();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 10/Question10_7/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 10/Question10_7/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 11/Question11_2/Machine.java:
--------------------------------------------------------------------------------
1 | package Question11_2;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class Machine {
6 | public ArrayList persons = new ArrayList();
7 | public int machineID;
8 | }
9 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 11/Question11_2/Server.java:
--------------------------------------------------------------------------------
1 | package Question11_2;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class Server {
6 | ArrayList machines = new ArrayList();
7 | }
8 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 11/Question11_3/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 11/Question11_3/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 11/Question11_4/BitSet.java:
--------------------------------------------------------------------------------
1 | package Question11_4;
2 |
3 | class BitSet {
4 | int[] bitset;
5 |
6 | public BitSet(int size) {
7 | bitset = new int[size >> 5]; // divide by 32
8 | }
9 |
10 | boolean get(int pos) {
11 | int wordNumber = (pos >> 5); // divide by 32
12 | int bitNumber = (pos & 0x1F); // mod 32
13 | return (bitset[wordNumber] & (1 << bitNumber)) != 0;
14 | }
15 |
16 | void set(int pos) {
17 | int wordNumber = (pos >> 5); // divide by 32
18 | int bitNumber = (pos & 0x1F); // mod 32
19 | bitset[wordNumber] |= 1 << bitNumber;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 11/Question11_4/Question.java:
--------------------------------------------------------------------------------
1 | package Question11_4;
2 |
3 | import CareerCupLibrary.AssortedMethods;
4 |
5 | public class Question {
6 |
7 | public static void checkDuplicates(int[] array) {
8 | BitSet bs = new BitSet(32000);
9 | for (int i = 0; i < array.length; i++) {
10 | int num = array[i];
11 | int num0 = num - 1; // bitset starts at 0, numbers start at 1
12 | if (bs.get(num0)) {
13 | System.out.println(num);
14 | } else {
15 | bs.set(num0);
16 | }
17 | }
18 | }
19 |
20 | public static void main(String[] args) {
21 | int[] array = AssortedMethods.randomArray(30, 1, 30);
22 | System.out.println(AssortedMethods.arrayToString(array));
23 | checkDuplicates(array);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 18/Question18_4/MyThread.java:
--------------------------------------------------------------------------------
1 | package Question18_4;
2 |
3 | import java.util.ArrayList;
4 |
5 | class MyThread extends Thread {
6 | long time;
7 | ArrayList res = new ArrayList();
8 | public ArrayList getRes() {
9 | return res;
10 | }
11 |
12 | public void run() {
13 | /* Run infinitely */
14 | time = System.currentTimeMillis();
15 | int count = 0;
16 | while (true) {
17 | if (count < 4){
18 | if (Question.canAcquireResource(this, Question.r[count])) {
19 | res.add(Question.r[count]);
20 | count++;
21 | System.out.println("Resource: [" + Question.r[count - 1].getId() + "] acquired by thread: [" + this.getName() + "]");
22 | try {
23 | sleep(1000);
24 | } catch (InterruptedException e) {
25 | e.printStackTrace();
26 | }
27 | }
28 | }
29 | else {
30 | this.stop();
31 | }
32 | }
33 | }
34 |
35 | public long getTime() {
36 | return time;
37 | }
38 | public void setRes(ArrayList res) {
39 | this.res = res;
40 | }
41 | MyThread(String name) {
42 | super(name);
43 | }
44 | }
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 18/Question18_4/Question.java:
--------------------------------------------------------------------------------
1 | package Question18_4;
2 |
3 | public class Question {
4 | /* Resources */
5 | static Resource r[] = new Resource[4];
6 | /* Threads */
7 | static MyThread th1 = new MyThread("Thread 1");
8 | static MyThread th2 = new MyThread("Thread 2");
9 |
10 | public static boolean canAcquireResource(MyThread t, Resource r){
11 | MyThread ot = null;
12 | if (t.getName().equals("Thread 1")) {
13 | ot = th2;
14 | }
15 | else{
16 | ot = th1;
17 | }
18 | if(ot == null) return true;
19 | if(!ot.getRes().contains(r)) return true;
20 | if(t.getTime() < ot.getTime()){
21 | while(t.isAlive()){
22 | System.out.println("Thread: ["+ot.getName()+ "] is waiting..");
23 | }
24 | return true;
25 | }
26 | else{
27 | System.out.println("Thread exiting: [" + t.getName()+"]");
28 | t.stop();
29 | }
30 | return false;
31 | }
32 |
33 | public static void main(String args[]){
34 | /* Create the resources */
35 | r[0] = new Resource(0);
36 | r[1] = new Resource(1);
37 | r[2] = new Resource(2);
38 | r[3] = new Resource(3);
39 | /* Start the threads */
40 | th1.start();
41 | th2.start();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 18/Question18_4/Resource.java:
--------------------------------------------------------------------------------
1 | package Question18_4;
2 |
3 | class Resource {
4 | long id;
5 |
6 | public Resource(long id){
7 | this.id = id;
8 | }
9 |
10 | public long getId() {
11 | return id;
12 | }
13 |
14 | public void setId(long id) {
15 | this.id = id;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 19/Question19_1/Question.java:
--------------------------------------------------------------------------------
1 | package Question19_1;
2 |
3 | public class Question {
4 |
5 | public static void swap(int a, int b) {
6 | a = b - a; // 9 - 5 = 4
7 | b = b - a; // 9 - 4 = 5
8 | a = a + b; // 4 + 5 = 9
9 |
10 | System.out.println("a: " + a);
11 | System.out.println("b: " + b);
12 | }
13 |
14 | public static void swap_opt(int a, int b) {
15 | a = a^b;
16 | b = a^b;
17 | a = a^b;
18 |
19 | System.out.println("a: " + a);
20 | System.out.println("b: " + b);
21 | }
22 |
23 | public static void main(String[] args) {
24 | int a = 1672;
25 | int b = 9332;
26 |
27 | System.out.println("a: " + a);
28 | System.out.println("b: " + b);
29 |
30 | swap(a, b);
31 | swap_opt(a, b);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 19/Question19_10/Question.java:
--------------------------------------------------------------------------------
1 | package Question19_10;
2 |
3 | public class Question {
4 | public static int rand7() {
5 | while (true) {
6 | int num = 5 * (rand5() - 1) + (rand5() - 1);
7 | if (num < 21) return (num % 7 + 1);
8 | }
9 | }
10 |
11 | public static int rand5() {
12 | return (int) (Math.random() * 100) % 5 + 1;
13 | }
14 |
15 | public static void main(String[] args) {
16 | /* Test: call rand7 many times and inspect the results. */
17 | int[] arr = new int[7];
18 | int test_size = 1000000;
19 | for(int k = 0; k < test_size; k++){
20 | arr[rand7() - 1]++;
21 | }
22 |
23 | int expected = test_size / 7;
24 |
25 | for (int i = 0; i < 7; i++) {
26 | int k = i + 1;
27 | int diff = arr[i] - expected;
28 | double percent = 100.0 * arr[i] / test_size;
29 | System.out.println(k + " appeared " + percent + "% of the time.");
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 19/Question19_11/Question.java:
--------------------------------------------------------------------------------
1 | package Question19_11;
2 |
3 | import java.util.Arrays;
4 |
5 | public class Question {
6 | public static void printPairSums(int[] array, int sum) {
7 | Arrays.sort(array);
8 | int first = 0;
9 | int last = array.length - 1;
10 | while (first < last) {
11 | int s = array[first] + array[last];
12 | if (s == sum) {
13 | System.out.println(array[first] + " " + array[last]);
14 | ++first;
15 | --last;
16 | } else {
17 | if (s < sum) {
18 | ++first;
19 | } else {
20 | --last;
21 | }
22 | }
23 | }
24 | }
25 |
26 | public static void main(String[] args) {
27 | int[] test = {9, 3, 6, 5, 7, -1, 13, 14, -2, 12, 0};
28 | printPairSums(test, 12);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 19/Question19_2/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 19/Question19_2/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 19/Question19_3/Question.java:
--------------------------------------------------------------------------------
1 | package Question19_3;
2 |
3 | public class Question {
4 | public static int numZeros(int num) {
5 | int count = 0;
6 | if (num < 0) {
7 | System.out.println("Factorial is not defined for negative numbers");
8 | return 0;
9 | }
10 | for (int i = 5; num / i > 0; i *= 5) {
11 | count += num / i;
12 | }
13 | return count;
14 | }
15 |
16 | public static int fact1(int num) {
17 | if (num == 1) {
18 | return 1;
19 | } else if (num > 1) {
20 | return num * fact1(num - 1);
21 | } else {
22 | return -1; // Error
23 | }
24 | }
25 |
26 | public static void main(String[] args) {
27 | for (int i = 1; i < 12; i++) {
28 | System.out.println(i + "! (or " + fact1(i) + ") has " + numZeros(i) + " zeros");
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 19/Question19_4/Question.java:
--------------------------------------------------------------------------------
1 | package Question19_4;
2 |
3 | public class Question {
4 |
5 | public static int getMax(int a, int b) {
6 | int c = a - b;
7 | int k = (c >> 31) & 0x1;
8 | int max = a - k * c;
9 | return max;
10 | }
11 |
12 | public static void main(String[] args) {
13 | int a = 103217;
14 | int b = 242239;
15 | System.out.println("max(" + a + ", " + b + ") = " + getMax(a, b));
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 19/Question19_5/Question.java:
--------------------------------------------------------------------------------
1 | package Question19_5;
2 |
3 | public class Question {
4 |
5 | public static class Result {
6 | public int hits;
7 | public int pseudoHits;
8 |
9 | public String toString() {
10 | return "(" + hits + ", " + pseudoHits + ")";
11 | }
12 | };
13 |
14 | public static Result estimate(String guess, String solution) {
15 | Result res = new Result();
16 | int solution_mask = 0;
17 | for (int i = 0; i < 4; ++i) {
18 | solution_mask |= 1 << (1 + solution.charAt(i) - 'A');
19 | }
20 | for (int i = 0; i < 4; ++i) {
21 | if (guess.charAt(i) == solution.charAt(i)) {
22 | ++res.hits;
23 | } else if ((solution_mask & ( 1 << (1 + guess.charAt(i) - 'A'))) >= 1) {
24 | ++res.pseudoHits;
25 | }
26 | }
27 | return res;
28 | }
29 | public static void main(String[] args) {
30 | // TODO Auto-generated method stub
31 | Result res = estimate("YRGB", "RGGB");
32 | System.out.println(res.toString());
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 19/Question19_7/Question.java:
--------------------------------------------------------------------------------
1 | package Question19_7;
2 |
3 | public class Question {
4 |
5 | public static int getMaxSum(int[] a) {
6 | int maxsum = 0;
7 | int sum = 0;
8 | for (int i = 0; i < a.length; i++) {
9 | sum += a[i];
10 | if (maxsum < sum) {
11 | maxsum = sum;
12 | } else if (sum < 0) {
13 | sum = 0;
14 | }
15 | }
16 | return maxsum;
17 | }
18 |
19 | public static void main(String[] args) {
20 | int[] a = {2, -8, 3, -2, 4, -10};
21 | System.out.println(getMaxSum(a));
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 2/Question2_1/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 2/Question2_1/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 2/Question2_2/Question.java:
--------------------------------------------------------------------------------
1 | package Question2_2;
2 |
3 | import CareerCupLibrary.*;
4 |
5 | public class Question {
6 |
7 | public static LinkedListNode nthToLast(LinkedListNode head, int n) {
8 | if (head == null || n < 1) {
9 | return null;
10 | }
11 |
12 | LinkedListNode p1 = head;
13 | LinkedListNode p2 = head;
14 | for (int j = 0; j < n - 1; ++j) { // skip n-1 steps ahead
15 | if (p2 == null) {
16 | return null; // not found since list size < n
17 | }
18 | p2 = p2.next;
19 | }
20 | if (p2 == null) {
21 | return null;
22 | }
23 | while (p2.next != null) {
24 | p1 = p1.next;
25 | p2 = p2.next;
26 | }
27 | return p1;
28 | }
29 |
30 | public static void main(String[] args) {
31 | LinkedListNode head = AssortedMethods.randomLinkedList(10, 0, 10);
32 | System.out.println(head.printForward());
33 | int nth = 12;
34 | LinkedListNode n = nthToLast(head, nth);
35 | if (n != null) {
36 | System.out.println(nth + "th to last node is " + n.data);
37 | } else {
38 | System.out.println("null");
39 | }
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 2/Question2_3/Question.java:
--------------------------------------------------------------------------------
1 | package Question2_3;
2 |
3 | import CareerCupLibrary.AssortedMethods;
4 | import CareerCupLibrary.LinkedListNode;
5 |
6 | public class Question {
7 |
8 | public static boolean deleteNode(LinkedListNode n) {
9 | if (n == null || n.next == null) {
10 | return false; // Failure
11 | }
12 | LinkedListNode next = n.next;
13 | n.data = next.data;
14 | n.next = next.next;
15 | return true;
16 | }
17 |
18 | public static void main(String[] args) {
19 | LinkedListNode head = AssortedMethods.randomLinkedList(10, 0, 10);
20 | System.out.println(head.printForward());
21 | deleteNode(head.next.next.next.next); // delete node 4
22 | System.out.println(head.printForward());
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 20/Question20_1/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 20/Question20_1/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 20/Question20_11/Subsquare.java:
--------------------------------------------------------------------------------
1 | package Question20_11;
2 |
3 | public class Subsquare {
4 | public int row, column, size;
5 | public Subsquare(int r, int c, int sz) {
6 | row = r;
7 | column = c;
8 | size = sz;
9 | }
10 |
11 | public void print() {
12 | System.out.println("(" + row + ", " + column + ", " + size + ")");
13 | }
14 | }
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 20/Question20_13/Trie.java:
--------------------------------------------------------------------------------
1 | package Question20_13;
2 |
3 | import java.util.LinkedList;
4 |
5 | /* Implements a trie. We store the input list of words in tries so
6 | * that we can efficiently find words with a given prefix.
7 | */
8 | public class Trie
9 | {
10 | // The root of this trie.
11 | private TrieNode root;
12 |
13 | /* The only constructor for the Trie class. Takes a list of strings
14 | * as an argument, and constructs a trie that stores these strings.
15 | */
16 | public Trie(LinkedList list)
17 | {
18 | root = new TrieNode();
19 | for (String word : list)
20 | root.addWord(word);
21 | }
22 |
23 | /* Checks whether this trie contains a string with the prefix passed
24 | * in as argument.
25 | */
26 | public boolean contains (String prefix)
27 | {
28 | TrieNode lastNode = root;
29 | for (int i = 0; i< prefix.length(); i++) {
30 | lastNode = lastNode.getNode(prefix.charAt(i));
31 | if (lastNode == null)
32 | return false;
33 | }
34 | return true;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 20/Question20_2/Question.java:
--------------------------------------------------------------------------------
1 | package Question20_2;
2 |
3 | import CareerCupLibrary.AssortedMethods;
4 |
5 | public class Question {
6 |
7 | public static void shuffleArray(int[] cards){
8 | int temp;
9 | int index;
10 | for (int i = 0; i < cards.length; i++){
11 | index = (int) (Math.random() * (cards.length - i)) + i;
12 | temp = cards[i];
13 | cards[i] = cards[index];
14 | cards[index] = temp;
15 | }
16 | }
17 |
18 | public static void main(String[] args) {
19 | int[] cards = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
20 | System.out.println(AssortedMethods.arrayToString(cards));
21 | shuffleArray(cards);
22 | System.out.println(AssortedMethods.arrayToString(cards));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 20/Question20_3/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 20/Question20_3/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 20/Question20_7/LengthComparator.java:
--------------------------------------------------------------------------------
1 | package Question20_7;
2 |
3 | import java.util.Comparator;
4 |
5 | public class LengthComparator implements Comparator {
6 | public int compare(String o1, String o2) {
7 | if (o1.length() < o2.length()) return 1;
8 | if (o1.length() > o2.length()) return -1;
9 | return 0;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 20/Question20_7/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 20/Question20_7/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 20/Question20_8/Question.java:
--------------------------------------------------------------------------------
1 | package Question20_8;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class Question {
6 | public static void main(String[] args) {
7 | String testString = "mississippi";
8 | String[] stringList = {"is", "sip", "hi", "sis"};
9 | SuffixTree tree = new SuffixTree(testString);
10 | for (String s : stringList) {
11 | ArrayList list = tree.getIndexes(s);
12 | if (list != null) {
13 | System.out.println(s + ": " + list.toString());
14 | }
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 20/Question20_8/SuffixTree.java:
--------------------------------------------------------------------------------
1 | package Question20_8;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class SuffixTree {
6 | SuffixTreeNode root = new SuffixTreeNode();
7 |
8 | public SuffixTree(String s) {
9 | for (int i = 0; i < s.length(); i++) {
10 | String suffix = s.substring(i);
11 | root.insertString(suffix, i);
12 | }
13 | }
14 |
15 | public ArrayList getIndexes(String s) {
16 | return root.getIndexes(s);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 20/Question20_9/MaxHeapComparator.java:
--------------------------------------------------------------------------------
1 | package Question20_9;
2 |
3 | import java.util.Comparator;
4 |
5 | public class MaxHeapComparator implements Comparator{
6 | // Comparator that sorts integers from highest to lowest
7 | @Override
8 | public int compare(Integer o1, Integer o2) {
9 | // TODO Auto-generated method stub
10 | if (o1 < o2) return 1;
11 | else if (o1 == o2) return 0;
12 | else return -1;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 20/Question20_9/MinHeapComparator.java:
--------------------------------------------------------------------------------
1 | package Question20_9;
2 |
3 | import java.util.Comparator;
4 |
5 | public class MinHeapComparator implements Comparator{
6 | // Comparator that sorts integers from lowest to highest
7 | @Override
8 | public int compare(Integer o1, Integer o2) {
9 | if (o1 > o2) return 1;
10 | else if (o1 == o2) return 0;
11 | else return -1;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 3/Question3_1/StackNode.java:
--------------------------------------------------------------------------------
1 | package Question3_1;
2 |
3 | class StackNode {
4 | public int previous;
5 | public int value;
6 | public StackNode(int p, int v){
7 | value = v;
8 | previous = p;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 3/Question3_2/NodeWithMin.java:
--------------------------------------------------------------------------------
1 | package Question3_2;
2 |
3 | class NodeWithMin {
4 | public int value;
5 | public int min;
6 | public NodeWithMin(int v, int min){
7 | value = v;
8 | this.min = min;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 3/Question3_2/Question.java:
--------------------------------------------------------------------------------
1 | package Question3_2;
2 |
3 | import CareerCupLibrary.AssortedMethods;
4 |
5 | public class Question {
6 | public static void main(String[] args) {
7 | StackWithMin stack = new StackWithMin();
8 | StackWithMin2 stack2 = new StackWithMin2();
9 | for (int i = 0; i < 15; i++) {
10 | int value = AssortedMethods.randomIntInRange(0, 100);
11 | stack.push(value);
12 | stack2.push(value);
13 | System.out.print(value + ", ");
14 | }
15 | System.out.println('\n');
16 | for (int i = 0; i < 15; i++) {
17 | System.out.println("Popped " + stack.pop().value + ", " + stack2.pop());
18 | System.out.println("New min is " + stack.min() + ", " + stack2.min());
19 | }
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 3/Question3_2/StackWithMin.java:
--------------------------------------------------------------------------------
1 | package Question3_2;
2 |
3 | import java.util.Stack;
4 |
5 | public class StackWithMin extends Stack {
6 | public void push(int value) {
7 | int newMin = Math.min(value, min());
8 | super.push(new NodeWithMin(value, newMin));
9 | }
10 |
11 | public int min() {
12 | if (this.isEmpty()) {
13 | return Integer.MAX_VALUE;
14 | } else {
15 | return peek().min;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 3/Question3_2/StackWithMin2.java:
--------------------------------------------------------------------------------
1 | package Question3_2;
2 |
3 | import java.util.Stack;
4 |
5 | public class StackWithMin2 extends Stack {
6 | Stack s2;
7 | public StackWithMin2() {
8 | s2 = new Stack();
9 | }
10 | public void push(int value){
11 | if (value <= min()) {
12 | s2.push(value);
13 | }
14 | super.push(value);
15 | }
16 | public Integer pop() {
17 | int value = super.pop();
18 | if (value == min()) {
19 | s2.pop();
20 | }
21 | return value;
22 | }
23 | public int min() {
24 | if (s2.isEmpty()) {
25 | return Integer.MAX_VALUE;
26 | } else {
27 | return s2.peek();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 3/Question3_3/Node.java:
--------------------------------------------------------------------------------
1 | package Question3_3;
2 |
3 | public class Node {
4 | public Node above;
5 | public Node below;
6 | public int value;
7 | public Node(int value) {
8 | this.value = value;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 3/Question3_3/Question.java:
--------------------------------------------------------------------------------
1 | package Question3_3;
2 |
3 | public class Question {
4 | public static void main(String[] args) {
5 | int capacity_per_substack = 5;
6 | SetOfStacks set = new SetOfStacks(capacity_per_substack);
7 | for (int i = 0; i < 34; i++) {
8 | set.push(i);
9 | }
10 | for (int i = 0; i < 34; i++) {
11 | System.out.println("Popped " + set.pop());
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 3/Question3_3/Stack.java:
--------------------------------------------------------------------------------
1 | package Question3_3;
2 |
3 | public class Stack {
4 | private int capacity;
5 | public Node top;
6 | public Node bottom;
7 | public int size = 0;
8 |
9 | public Stack(int capacity) { this.capacity = capacity; }
10 | public boolean isAtCapacity() { return capacity == size; }
11 |
12 | public void join(Node above, Node below) {
13 | if (below != null) below.above = above;
14 | if (above != null) above.below = below;
15 | }
16 |
17 | public boolean push(int v) {
18 | if (size >= capacity) return false;
19 | size++;
20 | Node n = new Node(v);
21 | if (size == 1) bottom = n;
22 | join(n, top);
23 | top = n;
24 | return true;
25 | }
26 |
27 | public int pop() {
28 | Node t = top;
29 | top = top.below;
30 | size--;
31 | return t.value;
32 | }
33 |
34 | public boolean isEmpty() { return size == 0; }
35 |
36 | public int removeBottom() {
37 | Node b = bottom;
38 | bottom = bottom.above;
39 | if (bottom != null) bottom.below = null;
40 | size--;
41 | return b.value;
42 | }
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 3/Question3_4/Question.java:
--------------------------------------------------------------------------------
1 | package Question3_4;
2 |
3 | public class Question {
4 | public static void main(String[] args) {
5 | // Set up code.
6 | int n = 5;
7 | Tower[] towers = new Tower[n];
8 | for (int i = 0; i < 3; i++) towers[i] = new Tower(i);
9 | for (int i = n - 1; i >= 0; i--) towers[0].add(i);
10 | towers[0].moveDisks(n, towers[2], towers[1]);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 3/Question3_4/Tower.java:
--------------------------------------------------------------------------------
1 | package Question3_4;
2 |
3 | import java.util.Stack;
4 |
5 | public class Tower {
6 | private Stack disks;
7 | private int index;
8 | public Tower(int i) {
9 | disks = new Stack();
10 | index = i;
11 | }
12 |
13 | public int index() {
14 | return index;
15 | }
16 |
17 | public void add(int d) {
18 | if (!disks.isEmpty() && disks.peek() <= d) {
19 | System.out.println("Error placing disk " + d);
20 | } else {
21 | disks.push(d);
22 | }
23 | }
24 |
25 | public void moveTopTo(Tower t) {
26 | int top = disks.pop();
27 | t.add(top);
28 | System.out.println("Move disk " + top + " from " + index() + " to " + t.index());
29 | }
30 |
31 | public void print() {
32 | System.out.println("Contents of Tower " + index());
33 | for (int i = disks.size() - 1; i >= 0; i--) {
34 | System.out.println(" " + disks.get(i));
35 | }
36 | }
37 |
38 | public void moveDisks(int n, Tower destination, Tower buffer){
39 | if (n > 0) {
40 | moveDisks(n - 1, buffer, destination);
41 | moveTopTo(destination);
42 | buffer.moveDisks(n - 1, destination, this);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 3/Question3_6/Question.java:
--------------------------------------------------------------------------------
1 | package Question3_6;
2 |
3 | import java.util.Stack;
4 |
5 | public class Question {
6 |
7 | public static Stack sort(Stack s) {
8 | Stack r = new Stack();
9 | while(!s.isEmpty()) {
10 | int tmp = s.pop();
11 | while(!r.isEmpty() && r.peek() > tmp) {
12 | s.push(r.pop());
13 | }
14 | r.push(tmp);
15 | }
16 | return r;
17 | }
18 |
19 | public static void main(String [] args) {
20 | Stack s = new Stack();
21 | s.push(3);
22 | s.push(2);
23 | s.push(24);
24 | s.push(34);
25 | s.push(19);
26 | s.push(3);
27 | s.push(4);
28 | s = sort(s);
29 | while(!s.isEmpty()) {
30 | System.out.println(s.pop());
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 4/Question4_2/Graph.java:
--------------------------------------------------------------------------------
1 | package Question4_2;
2 |
3 | public class Graph {
4 | private Node vertices[];
5 | public int count;
6 | public Graph() {
7 | vertices = new Node[6];
8 | count = 0;
9 | }
10 |
11 | public void addNode(Node x) {
12 | if (count < 30) {
13 | vertices[count] = x;
14 | count++;
15 | } else {
16 | System.out.print("Graph full");
17 | }
18 | }
19 |
20 | public Node[] getNodes() {
21 | return vertices;
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 4/Question4_2/Node.java:
--------------------------------------------------------------------------------
1 | package Question4_2;
2 |
3 | class Node {
4 | private Node adjacent[];
5 | public int adjacentCount;
6 | private String vertex;
7 | public Question.State state;
8 | public Node(String vertex, int adjacentLength) {
9 | this.vertex = vertex;
10 | adjacentCount = 0;
11 | adjacent = new Node[adjacentLength];
12 | }
13 |
14 | public void addAdjacent(Node x) {
15 | if (adjacentCount < 30) {
16 | this.adjacent[adjacentCount] = x;
17 | adjacentCount++;
18 | } else {
19 | System.out.print("No more adjacent can be added");
20 | }
21 | }
22 | public Node[] getAdjacent() {
23 | return adjacent;
24 | }
25 | public String getVertex() {
26 | return vertex;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 4/Question4_3/Question.java:
--------------------------------------------------------------------------------
1 | package Question4_3;
2 |
3 | import CareerCupLibrary.TreeNode;
4 |
5 | public class Question {
6 | public static void main(String[] args) {
7 | int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
8 |
9 | // We needed this code for other files, so check out the code in the library
10 | TreeNode root = TreeNode.createMinimalBST(array);
11 | System.out.println("Root? " + root.data);
12 | System.out.println("Created BST? " + root.isBST());
13 | System.out.println("Height: " + root.height());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 4/Question4_5/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 4/Question4_5/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 4/Question4_6/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 4/Question4_6/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 4/Question4_7/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 4/Question4_7/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 5/Question5_1/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 5/Question5_1/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 5/Question5_2/Question.java:
--------------------------------------------------------------------------------
1 | package Question5_2;
2 |
3 | public class Question {
4 | public static String printBinary(String n) {
5 | int intPart = Integer.parseInt(n.substring(0, n.indexOf('.')));
6 | double decPart = Double.parseDouble(n.substring(n.indexOf('.'), n.length()));
7 | String int_string = "";
8 | while (intPart > 0) {
9 | int r = intPart % 2;
10 | intPart >>= 1;
11 | int_string = r + int_string;
12 | }
13 | /* Convert the decimal part */
14 | StringBuffer dec_string = new StringBuffer();
15 | while (decPart > 0) {
16 | if (dec_string.length() > 32) {
17 | return "ERROR";
18 | }
19 | if (decPart == 1) {
20 | dec_string.append((int)decPart);
21 | break;
22 | }
23 | double r = decPart * 2;
24 | if (r >= 1) {
25 | dec_string.append(1);
26 | decPart = r - 1;
27 | } else {
28 | dec_string.append(0);
29 | decPart = r;
30 | }
31 | }
32 | return int_string + "." + dec_string.toString();
33 | }
34 |
35 | public static void main(String[] args) {
36 | String n = "19.25";
37 | String bs = printBinary(n);
38 | System.out.println(bs);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 5/Question5_5/Question.java:
--------------------------------------------------------------------------------
1 | package Question5_5;
2 |
3 | import CareerCupLibrary.AssortedMethods;
4 |
5 | public class Question {
6 | public static int bitSwapRequired(int a, int b) {
7 | int count = 0;
8 | for (int c = a ^ b; c != 0; c = c >> 1) {
9 | count += c & 1;
10 | }
11 | return count;
12 | }
13 |
14 | public static void main(String[] args) {
15 | int a = 217;
16 | int b = 532;
17 | System.out.println(a + ": " + AssortedMethods.toFullBinaryString(a));
18 | System.out.println(b + ": " + AssortedMethods.toFullBinaryString(b));
19 | int nbits = bitSwapRequired(a, b);
20 | System.out.println("Required number of bits: " + nbits);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 5/Question5_6/Question.java:
--------------------------------------------------------------------------------
1 | package Question5_6;
2 |
3 | import CareerCupLibrary.AssortedMethods;
4 |
5 | public class Question {
6 |
7 | public static int swapOddEvenBits(int x) {
8 | return ( ((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1) );
9 | }
10 |
11 | public static void main(String[] args) {
12 | int a = 103217;
13 | System.out.println(a + ": " + AssortedMethods.toFullBinaryString(a));
14 | int b = swapOddEvenBits(a);
15 | System.out.println(b + ": " + AssortedMethods.toFullBinaryString(b));
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 5/Question5_7.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 5/Question5_7.zip
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_1/BlackJackCard.java:
--------------------------------------------------------------------------------
1 | package Question7_1;
2 |
3 | public class BlackJackCard extends Card {
4 | public BlackJackCard(int r, Suit s) {
5 | super(r, s);
6 | }
7 |
8 | public int value() {
9 | int r = super.value();
10 | if (r == 1) return 11; // aces are 11
11 | if (r < 10) return r;
12 | return 10;
13 | }
14 |
15 | boolean isAce() {
16 | return super.value() == 1;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_1/Card.java:
--------------------------------------------------------------------------------
1 | package Question7_1;
2 |
3 | public class Card {
4 | public enum Suit {
5 | CLUBS (1),
6 | SPADES (2),
7 | HEARTS (3),
8 | DIAMONDS (4);
9 |
10 | int value;
11 | private Suit(int v) { value = v; }
12 | };
13 |
14 | private int card;
15 | private Suit suit;
16 |
17 | public Card(int r, Suit s) {
18 | card = r;
19 | suit = s;
20 | }
21 |
22 | public int value() { return card; }
23 | public Suit suit() { return suit; }
24 | }
25 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_2/Call.java:
--------------------------------------------------------------------------------
1 | package Question7_2;
2 |
3 | class Call {
4 | int rank = 0; // minimal rank of employee who can handle this call
5 |
6 | public void reply(String message) {
7 | // play recorded message to the customer
8 | }
9 |
10 | public void disconnect() {
11 | reply("Thank you for calling");
12 | }
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_2/CallHandler.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 7/Question7_2/CallHandler.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_2/Employee.java:
--------------------------------------------------------------------------------
1 | package Question7_2;
2 |
3 | class Employee {
4 | CallHandler callHandler;
5 | int rank; // 0- fresher, 1 - technical lead, 2 - product manager
6 | boolean free;
7 |
8 | public Employee(int rank) {
9 | this.rank = rank;
10 | }
11 |
12 | // start the conversation
13 | void ReceiveCall(Call call) {
14 | free = false;
15 | }
16 |
17 | // the issue is resolved, finish the call
18 | void CallHandled(Call call) {
19 | call.disconnect();
20 | free = true;
21 | // look if there is a call waiting in queue
22 | callHandler.getNextCall(this);
23 | }
24 |
25 | // the issue is not resolved, escalate the call
26 | void CannotHandle(Call call) {
27 | call.rank = rank + 1;
28 | callHandler.dispatchCall(call);
29 | free = true;
30 | // look if there is a call waiting in queue
31 | callHandler.getNextCall(this);
32 | }
33 | }
34 |
35 |
36 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_2/Fresher.java:
--------------------------------------------------------------------------------
1 | package Question7_2;
2 |
3 | class Fresher extends Employee {
4 | public Fresher() {
5 | super(0);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_2/ProductManager.java:
--------------------------------------------------------------------------------
1 | package Question7_2;
2 |
3 | class ProductManager extends Employee {
4 | public ProductManager() {
5 | super(2);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_2/TechLead.java:
--------------------------------------------------------------------------------
1 | package Question7_2;
2 |
3 | class TechLead extends Employee {
4 | public TechLead() {
5 | super(1);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_3/CD.java:
--------------------------------------------------------------------------------
1 | package Question7_3;
2 |
3 | public class CD {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_3/CDPlayer.java:
--------------------------------------------------------------------------------
1 | package Question7_3;
2 |
3 | public class CDPlayer {
4 | private Playlist p;
5 | private CD c;
6 |
7 | public Playlist getPlaylist() { return p; }
8 | public void setPlaylist(Playlist p) { this.p = p; }
9 | public CD getCD() { return c; }
10 | public void setCD(CD c) { this.c = c; }
11 |
12 | public CDPlayer(Playlist p) { this.p = p; }
13 | public CDPlayer(CD c, Playlist p) {
14 | this.p = p;
15 | this.c = c;
16 | }
17 |
18 | public CDPlayer(CD c){ this.c = c; }
19 | public void playTrack(Song s) { }
20 | }
21 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_3/JukeBox.java:
--------------------------------------------------------------------------------
1 | package Question7_3;
2 |
3 | import java.util.Set;
4 |
5 | public class JukeBox {
6 | private CDPlayer cdPlayer;
7 | private User user;
8 | private Set cdCollection;
9 | private TrackSelector ts;
10 |
11 | public JukeBox(CDPlayer cdPlayer, User user, Set cdCollection,
12 | TrackSelector ts) {
13 | super();
14 | this.cdPlayer = cdPlayer;
15 | this.user = user;
16 | this.cdCollection = cdCollection;
17 | this.ts = ts;
18 | }
19 |
20 | public Song getCurrentTrack() { return ts.getCurrentSong(); }
21 | public void processOneUser(User u) { this.user = u; }
22 | }
23 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_3/Playlist.java:
--------------------------------------------------------------------------------
1 | package Question7_3;
2 |
3 | import java.util.Queue;
4 |
5 | public class Playlist {
6 | private Song track;
7 | private Queue queue;
8 | public Playlist(Song track, Queue queue) {
9 | super();
10 | this.track = track;
11 | this.queue = queue;
12 | }
13 |
14 | public Song getNextTrackToPlay(){ return queue.peek(); }
15 | public void queueUpTrack(Song s){ queue.add(s); }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_3/Song.java:
--------------------------------------------------------------------------------
1 | package Question7_3;
2 |
3 | public class Song {
4 | private String songName;
5 | public String toString() { return songName; }
6 | }
7 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_3/TrackSelector.java:
--------------------------------------------------------------------------------
1 | package Question7_3;
2 |
3 |
4 | public class TrackSelector {
5 | private Song currentSong;
6 | public TrackSelector(Song s) { currentSong=s; }
7 | public void setTrack(Song s) { currentSong = s; }
8 | public Song getCurrentSong() { return currentSong; }
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_3/User.java:
--------------------------------------------------------------------------------
1 | package Question7_3;
2 |
3 | public class User {
4 | private String name;
5 | public String getName() { return name; }
6 | public void setName(String name) { this.name = name; }
7 | public long getID() { return ID; }
8 | public void setID(long iD) { ID = iD; }
9 | private long ID;
10 | public User(String name, long iD) {
11 | this.name = name;
12 | ID = iD;
13 | }
14 | public User getUser() { return this; }
15 | public static User addUser(String name, long iD){
16 | return new User(name, iD);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/ChessFormat.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | //include info about timing, etc.
4 | public class ChessFormat {
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/ChessPieceBase.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | public abstract class ChessPieceBase {
4 | abstract void estimationParameter0(); /* used by PositionEstimater in different circumstances */
5 | abstract int estimationParameter1();
6 | abstract boolean canBeChecked();
7 | abstract boolean isSupportCastle();
8 | // other rule-base properties
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/ChessPieceTurn.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | public class ChessPieceTurn {
4 |
5 | };
6 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/ComputerPlayer.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | class ComputerPlayer extends PlayerBase {
4 | public ChessPieceTurn getTurn(Position p) { return null; }
5 | public void setDifficulty() { };
6 | public PositionEstimator estimater;
7 | public PositionBackTracker backtracter;
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/GameManager.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | public class GameManager { // keeps track of time, end of the game, etc
4 | void processTurn(PlayerBase player) { };
5 | boolean acceptTurn(ChessPieceTurn turn) { return true; };
6 |
7 | Position currentPosition;
8 | ChessFormat format;
9 | public void setGameLog(String filePath) { };
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/HumanPlayer.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | public class HumanPlayer extends PlayerBase {
4 | public ChessPieceTurn getTurn(Position p) { return null; }
5 | }
6 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/King.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | public class King extends ChessPieceBase {
4 | void estimationParameter0() { };
5 | int estimationParameter1() { return 0; }
6 | boolean canBeChecked() { return false; }
7 | boolean isSupportCastle() { return false; }
8 | }
9 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/PlayerBase.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | public abstract class PlayerBase {
4 | public abstract ChessPieceTurn getTurn(Position p);
5 | }
6 |
7 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/Position.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class Position { // represents chess positions in compact form
6 | ArrayList black;
7 | ArrayList white;
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/PositionBackTracker.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | public class PositionBackTracker {
4 | // get next position for estimation.
5 | public static Position getNext(Position p) { return null; }
6 | }
7 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/PositionEstimator.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | public class PositionEstimator {
4 | // calculate value of a position
5 | public static PositionPotentialValue estimate(Position p) { return null; }
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/PositionPotentialValue.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | public abstract class PositionPotentialValue {
4 | /* compares value of potential game position */
5 | abstract boolean lessThan(PositionPotentialValue pv);
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_4/Queen.java:
--------------------------------------------------------------------------------
1 | package Question7_4;
2 |
3 | public class Queen extends ChessPieceBase {
4 | void estimationParameter0() { };
5 | int estimationParameter1() { return 0; }
6 | boolean canBeChecked() { return false; }
7 | boolean isSupportCastle() { return false; }
8 | }
9 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_5/Book.java:
--------------------------------------------------------------------------------
1 | package Question7_5;
2 |
3 | import java.util.Set;
4 |
5 | public class Book {
6 | private long ID;
7 | private String details;
8 | private static Set books;
9 |
10 | public Book(long iD, String details) {
11 | ID = iD;
12 | this.details = details;
13 | }
14 |
15 | public static void addBook(long iD, String details){
16 | books.add(new Book(iD,details));
17 | }
18 |
19 | public void update() { }
20 |
21 | public static void delete(Book b){
22 | books.remove(b);
23 | }
24 |
25 | public static Book find(long id){
26 | for (Book b : books) {
27 | if(b.getID() == id) return b;
28 | }
29 | return null;
30 | }
31 |
32 | public long getID() { return ID; }
33 | public void setID(long iD) { ID = iD; }
34 | public String getDetails() { return details; }
35 | public void setDetails(String details) { this.details = details; }
36 | }
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_5/OnlineReaderSystem.java:
--------------------------------------------------------------------------------
1 | package Question7_5;
2 |
3 | public class OnlineReaderSystem {
4 | private Book b;
5 | private User u;
6 | public OnlineReaderSystem(Book b, User u) {
7 | this.b = b;
8 | this.u = u;
9 | }
10 |
11 | public void listenRequest() { }
12 | public Book searchBook(long ID) { return Book.find(ID); }
13 | public User searchUser(long ID){ return User.find(ID); }
14 | public void display() { }
15 | public Book getBook() { return b; }
16 | public void setBook(Book b) { this.b = b; }
17 | public User getUser() { return u; }
18 | public void setUser(User u) { this.u = u; }
19 | }
20 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_5/User.java:
--------------------------------------------------------------------------------
1 | package Question7_5;
2 |
3 | import java.util.Set;
4 |
5 | public class User {
6 | private long ID;
7 | private String details;
8 | private int accountType;
9 | private static Set users;
10 |
11 | public Book searchLibrary(long id){ return Book.find(id); }
12 | public void renewMembership() { }
13 |
14 | public static User find(long ID) {
15 | for (User u:users) {
16 | if (u.getID() == ID) return u;
17 | }
18 | return null;
19 | }
20 |
21 | public static void addUser(long ID, String details,
22 | int accountType) {
23 | users.add(new User(ID,details,accountType));
24 | }
25 |
26 | public User(long iD, String details, int accountType) {
27 | ID = iD;
28 | this.details = details;
29 | this.accountType = accountType;
30 | }
31 | public long getID() { return ID; }
32 | public void setID(long iD) { ID = iD; }
33 | public String getDetails() { return details; }
34 | public void setDetails(String details) { this.details = details; }
35 | public int getAccountType() { return accountType; }
36 | public void setAccountType(int accountType) {
37 | this.accountType = accountType;
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 7/Question7_8/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 7/Question7_8/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 8/Question8_1/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 8/Question8_1/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 8/Question8_5/Question.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/Chapter 8/Question8_5/Question.java
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 8/Question8_7/Question.java:
--------------------------------------------------------------------------------
1 | package Question8_7;
2 |
3 | public class Question {
4 | public static int makeChange(int n, int denom) {
5 | int next_denom = 0;
6 | switch (denom) {
7 | case 25:
8 | next_denom = 10;
9 | break;
10 | case 10:
11 | next_denom = 5;
12 | break;
13 | case 5:
14 | next_denom = 1;
15 | break;
16 | case 1:
17 | return 1;
18 | }
19 | int ways = 0;
20 | for (int i = 0; i * denom <= n; i++) {
21 | ways += makeChange(n - i * denom, next_denom);
22 | }
23 | return ways;
24 | }
25 |
26 | public static int makeChange(int n) {
27 | return makeChange(n, 25);
28 | }
29 |
30 | public static void main(String[] args) {
31 | for (int i = 0; i < 100; i++) {
32 | System.out.println("makeChange(" + i + ") = " + makeChange(i));
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 8/Question8_8/Question.java:
--------------------------------------------------------------------------------
1 | package Question8_8;
2 |
3 | public class Question {
4 | static int columnForRow[] = new int [8];
5 | static boolean check(int row) {
6 | for (int i = 0; i < row; i++) {
7 | int diff = Math.abs(columnForRow[i] - columnForRow[row]);
8 | if (diff == 0 || diff == row - i) return false;
9 | }
10 | return true;
11 | }
12 |
13 | static void printBoard() {
14 | System.out.println("-----------------");
15 | for(int i = 0; i < 8; i++){
16 | System.out.print("|");
17 | for(int j = 0; j < 8; j++){
18 | if (columnForRow[i] == j) System.out.print("Q|");
19 | else System.out.print(" |");
20 | }
21 | System.out.println("\n-----------------");
22 | }
23 | System.out.println("");
24 | }
25 |
26 | static void PlaceQueen(int row){
27 | if (row == 8) {
28 | printBoard();
29 | return;
30 | }
31 | for (int i = 0; i < 8; i++) {
32 | columnForRow[row]=i;
33 | if(check(row)){
34 | PlaceQueen(row+1);
35 | }
36 | }
37 | }
38 |
39 | public static void main(String[] args) {
40 | PlaceQueen(0);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 9/Question9_1/Question.java:
--------------------------------------------------------------------------------
1 | package Question9_1;
2 |
3 | import CareerCupLibrary.AssortedMethods;
4 |
5 | public class Question {
6 |
7 |
8 | /** Merges array
9 | * @param a first array
10 | * @param b second array
11 | * @param n number of "real" elements in a
12 | * @param m number of "real" elements in b
13 | */
14 | public static void merge(int[] a, int[] b, int n, int m) {
15 | int k = m + n - 1; // Index of last location of array b
16 | int i = n - 1; // Index of last element in array b
17 | int j = m - 1; // Index of last element in array a
18 |
19 | // Start comparing from the last element and merge a and b
20 | while (i >= 0 && j >= 0) {
21 | if (a[i] > b[j]) {
22 | a[k--] = a[i--];
23 | } else {
24 | a[k--] = b[j--];
25 | }
26 | }
27 | while (j >= 0) {
28 | a[k--] = b[j--];
29 | }
30 | }
31 |
32 | public static void main(String[] args) {
33 | int[] a = {1, 3, 4, 5, 6, 8, 10, 0, 0, 0, 0, 0};
34 | int[] b = {4, 7, 9, 10, 12};
35 | merge(a, b, 7, 5);
36 | System.out.println(AssortedMethods.arrayToString(a));
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 9/Question9_2/AnagramComparator.java:
--------------------------------------------------------------------------------
1 | package Question9_2;
2 |
3 | import java.util.Arrays;
4 | import java.util.Comparator;
5 |
6 | public class AnagramComparator implements Comparator {
7 | public String sortChars(String s) {
8 | char[] content = s.toCharArray();
9 | Arrays.sort(content);
10 | return new String(content);
11 | }
12 |
13 | public int compare(String s1, String s2) {
14 | return sortChars(s1).compareTo(sortChars(s2));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 9/Question9_2/Question.java:
--------------------------------------------------------------------------------
1 | package Question9_2;
2 |
3 | import java.util.Arrays;
4 |
5 | import CareerCupLibrary.AssortedMethods;
6 |
7 | public class Question {
8 | public static void main(String[] args) {
9 | String[] array = {"apple", "banana", "carrot", "ele", "duck", "papel", "tarroc", "cudk", "eel", "lee"};
10 | System.out.println(AssortedMethods.stringArrayToString(array));
11 | Arrays.sort(array, new AnagramComparator());
12 | System.out.println(AssortedMethods.stringArrayToString(array));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 9/Question9_3/Question.java:
--------------------------------------------------------------------------------
1 | package Question9_3;
2 |
3 | public class Question {
4 |
5 | public static int search(int a[], int l, int u, int x) {
6 | while (l <= u) {
7 | int m = (l + u) / 2;
8 | if (x == a[m]) {
9 | return m;
10 | } else if (a[l] <= a[m]) {
11 | if (x > a[m]) {
12 | l = m+1;
13 | } else if (x >=a [l]) {
14 | u = m-1;
15 | } else {
16 | l = m+1;
17 | }
18 | }
19 | else if (x < a[m]) u = m-1;
20 | else if (x <= a[u]) l = m+1;
21 | else u = m - 1;
22 | }
23 | return -1;
24 | }
25 |
26 | public static int search(int a[], int x) {
27 | return search(a, 0, a.length - 1, x);
28 | }
29 |
30 | public static void main(String[] args) {
31 | int[] a = {4, 5, 6, 7, 8, 9, 1, 2, 3};
32 | for (int x : a) {
33 | System.out.println(x + " is at position " + search(a, x));
34 | }
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 9/Question9_6/Question9_6.java:
--------------------------------------------------------------------------------
1 | package Question9_6;
2 | import CareerCupLibrary.*;
3 |
4 | public class Question9_6 {
5 |
6 | public static boolean FindElem(int[][] matrix, int elem) {
7 | int row = 0;
8 | int col = matrix[0].length - 1;
9 | while (row < matrix.length && col >= 0) {
10 | if (matrix[row][col] == elem) {
11 | return true;
12 | } else if (matrix[row][col] > elem) {
13 | col--;
14 | } else {
15 | row++;
16 | }
17 | }
18 | return false;
19 | }
20 |
21 | public static void main(String[] args) {
22 | int M = 10;
23 | int N = 5;
24 | int[][] matrix = new int[M][N];
25 | for (int i = 0; i < M; i++) {
26 | for (int j = 0; j < N; j++) {
27 | matrix[i][j] = 10 * i + j;
28 | }
29 | }
30 |
31 | AssortedMethods.printMatrix(matrix);
32 |
33 | for (int i = 0; i < M; i++) {
34 | for (int j = 0; j < M; j++) {
35 | int v = 10 * i + j;
36 | System.out.println(v + ": " + FindElem(matrix, v));
37 | }
38 | }
39 |
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/Chapter 9/Question9_7/HtWt.java:
--------------------------------------------------------------------------------
1 | package Question9_7;
2 |
3 | public class HtWt implements Comparable {
4 | private int Ht;
5 | private int Wt;
6 | public HtWt(int h, int w) { Ht = h; Wt = w; }
7 |
8 | public int compareTo( Object s ) {
9 | HtWt second = (HtWt) s;
10 | if (this.Ht != second.Ht) {
11 | return ((Integer)this.Ht).compareTo(second.Ht);
12 | } else {
13 | return ((Integer)this.Wt).compareTo(second.Wt);
14 | }
15 | }
16 |
17 | public String toString() {
18 | return "(" + Ht + ", " + Wt + ")";
19 | }
20 |
21 | public boolean isBefore(HtWt other) {
22 | if (this.Ht < other.Ht && this.Wt < other.Wt) {
23 | return true;
24 | } else {
25 | return false;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/CareerCupLibrary/AssortedMethods.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/CareerCupLibrary/AssortedMethods.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/CareerCupLibrary/BitVector.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/CareerCupLibrary/BitVector.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/CareerCupLibrary/LinkedListNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/CareerCupLibrary/LinkedListNode.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/CareerCupLibrary/TreeNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/CareerCupLibrary/TreeNode.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question10_3/Line.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question10_3/Line.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question10_3/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question10_3/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question10_4/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question10_4/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question10_5/Line.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question10_5/Line.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question10_5/Point.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question10_5/Point.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question10_5/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question10_5/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question10_5/Square.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question10_5/Square.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question10_6/GraphPoint.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question10_6/GraphPoint.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question10_6/Line.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question10_6/Line.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question10_6/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question10_6/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question10_7/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question10_7/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question11_2/Machine.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question11_2/Machine.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question11_2/Person.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question11_2/Person.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question11_2/Server.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question11_2/Server.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question11_3/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question11_3/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question11_4/BitSet.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question11_4/BitSet.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question11_4/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question11_4/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question18_4/MyThread.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question18_4/MyThread.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question18_4/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question18_4/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question18_4/Resource.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question18_4/Resource.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_1/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_1/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_10/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_10/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_11/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_11/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_2/Question$Check.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_2/Question$Check.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_2/Question$Piece.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_2/Question$Piece.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_2/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_2/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_3/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_3/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_4/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_4/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_5/Question$Result.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_5/Question$Result.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_5/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_5/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_6/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_6/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_7/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_7/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_8/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_8/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question19_9/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question19_9/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question1_1/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question1_1/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question1_3/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question1_3/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question1_4/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question1_4/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question1_5/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question1_5/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question1_6/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question1_6/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question1_7/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question1_7/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question1_8/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question1_8/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_1/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_1/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_10/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_10/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_11/Question20_10.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_11/Question20_10.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_11/Subsquare.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_11/Subsquare.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_12/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_12/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_13/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_13/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_13/Rectangle.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_13/Rectangle.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_13/Trie.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_13/Trie.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_13/TrieNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_13/TrieNode.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_13/WordGroup.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_13/WordGroup.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_2/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_2/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_3/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_3/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_4/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_4/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_5/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_5/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_7/LengthComparator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_7/LengthComparator.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_7/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_7/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_8/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_8/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_8/SuffixTree.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_8/SuffixTree.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_8/SuffixTreeNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_8/SuffixTreeNode.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_9/MaxHeapComparator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_9/MaxHeapComparator.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_9/MinHeapComparator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_9/MinHeapComparator.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question20_9/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question20_9/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question2_1/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question2_1/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question2_2/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question2_2/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question2_3/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question2_3/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question2_4/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question2_4/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question2_5/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question2_5/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_1/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_1/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_1/QuestionB.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_1/QuestionB.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_1/StackNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_1/StackNode.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_2/NodeWithMin.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_2/NodeWithMin.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_2/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_2/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_2/StackWithMin.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_2/StackWithMin.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_2/StackWithMin2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_2/StackWithMin2.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_3/Node.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_3/Node.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_3/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_3/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_3/SetOfStacks.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_3/SetOfStacks.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_3/Stack.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_3/Stack.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_4/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_4/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_4/Tower.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_4/Tower.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_5/MyQueue.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_5/MyQueue.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_5/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_5/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question3_6/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question3_6/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question4_1/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question4_1/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question4_2/Graph.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question4_2/Graph.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question4_2/Node.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question4_2/Node.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question4_2/Question$State.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question4_2/Question$State.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question4_2/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question4_2/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question4_3/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question4_3/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question4_4/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question4_4/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question4_5/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question4_5/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question4_6/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question4_6/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question4_7/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question4_7/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question4_8/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question4_8/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question5_1/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question5_1/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question5_2/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question5_2/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question5_3/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question5_3/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question5_5/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question5_5/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question5_6/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question5_6/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question5_7/BitInteger.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question5_7/BitInteger.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question5_7/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question5_7/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_1/BlackJackCard.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_1/BlackJackCard.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_1/Card$Suit.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_1/Card$Suit.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_1/Card.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_1/Card.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_2/Call.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_2/Call.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_2/CallHandler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_2/CallHandler.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_2/Employee.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_2/Employee.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_2/Fresher.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_2/Fresher.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_2/ProductManager.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_2/ProductManager.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_2/TechLead.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_2/TechLead.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_3/CD.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_3/CD.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_3/CDPlayer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_3/CDPlayer.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_3/JukeBox.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_3/JukeBox.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_3/Playlist.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_3/Playlist.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_3/Song.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_3/Song.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_3/TrackSelector.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_3/TrackSelector.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_3/User.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_3/User.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/ChessFormat.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/ChessFormat.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/ChessPieceBase.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/ChessPieceBase.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/ChessPieceTurn.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/ChessPieceTurn.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/ComputerPlayer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/ComputerPlayer.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/GameManager.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/GameManager.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/HumanPlayer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/HumanPlayer.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/King.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/King.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/PlayerBase.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/PlayerBase.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/Position.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/Position.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/PositionBackTracker.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/PositionBackTracker.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/PositionEstimator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/PositionEstimator.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/PositionPotentialValue.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/PositionPotentialValue.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_4/Queen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_4/Queen.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_5/Book.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_5/Book.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_5/OnlineReaderSystem.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_5/OnlineReaderSystem.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_5/User.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_5/User.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question7_8/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question7_8/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question8_1/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question8_1/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question8_2/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question8_2/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question8_3/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question8_3/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question8_4/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question8_4/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question8_5/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question8_5/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question8_6/Question$Color.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question8_6/Question$Color.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question8_6/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question8_6/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question8_7/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question8_7/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question8_8/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question8_8/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question9_1/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question9_1/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question9_2/AnagramComparator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question9_2/AnagramComparator.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question9_2/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question9_2/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question9_3/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question9_3/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question9_5/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question9_5/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question9_6/Question9_6.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question9_6/Question9_6.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question9_7/HtWt.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question9_7/HtWt.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/bin/Question9_7/Question.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/CTCI Edition 4 solutions/bin/Question9_7/Question.class
--------------------------------------------------------------------------------
/CTCI Edition 4 solutions/input_file_q11_4.txt:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 3
5 | 4
6 | 5
7 | 6
8 | 7
9 | 129
10 | 23
11 | 2334
12 | 23
13 | 232
14 | 11
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Amazon - Last 1 year based on Frequency.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Amazon - Last 1 year based on Frequency.pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Amazon - Last 2 year based on Frequency.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Amazon - Last 2 year based on Frequency.pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Amazon - Last 6 months based on Frequency.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Amazon - Last 6 months based on Frequency.pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Backtracking - LeetCode(Based on Frequency).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Backtracking - LeetCode(Based on Frequency).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Backtracking pattern - Questions & Soln (Subsets, Permutations, Combination Sum, Palindrome Partitioning).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Backtracking pattern - Questions & Soln (Subsets, Permutations, Combination Sum, Palindrome Partitioning).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Binary Search Tree - LeetCode(Based on Frequency).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Binary Search Tree - LeetCode(Based on Frequency).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Breadth-first Search - LeetCode(Based on Frequency).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Breadth-first Search - LeetCode(Based on Frequency).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Cisco - All time.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Cisco - All time.pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Cisco - last 1 year.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Cisco - last 1 year.pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Cisco - last 2 year.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Cisco - last 2 year.pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Cisco - last 6 months.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Cisco - last 6 months.pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Depth-first Search - LeetCode(Based on Frequency).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Depth-first Search - LeetCode(Based on Frequency).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Dynamic Programming - LeetCode(Based on Frequency).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Dynamic Programming - LeetCode(Based on Frequency).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Google - Last 1 year(based on Frequency).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Google - Last 1 year(based on Frequency).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Google - Last 6 months(based on Frequency).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Google - Last 6 months(based on Frequency).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Google Full Time Questions/Google Q1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Google Full Time Questions/Google Q1.PNG
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Google Full Time Questions/Google Q2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Google Full Time Questions/Google Q2.PNG
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Google Prep Q &A.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Google Prep Q &A.docx
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Heap - LeetCode(Based on Frequency).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Heap - LeetCode(Based on Frequency).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Linked List - LeetCode(Based on Frequency).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Linked List - LeetCode(Based on Frequency).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Oracle - LeetCode(all time).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Oracle - LeetCode(all time).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Oracle - LeetCode(last 1 year).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Oracle - LeetCode(last 1 year).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Oracle - LeetCode(last 6 months).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Oracle - LeetCode(last 6 months).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Queue - LeetCode(Based on Frequency).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Queue - LeetCode(Based on Frequency).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Stack - LeetCode(Based on Frequency).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Stack - LeetCode(Based on Frequency).pdf
--------------------------------------------------------------------------------
/Companies Qts & Topic wise Qts/Topological Sort - LeetCode.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Companies Qts & Topic wise Qts/Topological Sort - LeetCode.pdf
--------------------------------------------------------------------------------
/Cormen_Algorithms_3rd.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Cormen_Algorithms_3rd.pdf
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/1. Two Sum.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Given an array of integers, return indices of the two numbers such that they add up to a specific target.
4 |
5 | You may assume that each input would have exactly one solution, and you may not use the same element twice.
6 |
7 | Example:
8 |
9 | Given nums = [2, 7, 11, 15], target = 9,
10 |
11 | Because nums[0] + nums[1] = 2 + 7 = 9,
12 | return [0, 1].
13 |
14 | */
15 |
16 | import java.util.*;
17 |
18 | class Solution {
19 |
20 | public int[] twoSum(int[] nums, int target) {
21 | Map map = new HashMap<>();
22 | for (int i = 0; i < nums.length; i++) {
23 | int complement = target - nums[i];
24 | if (map.containsKey(complement)) {
25 | return new int[]{map.get(complement), i};
26 | }
27 | map.put(nums[i], i);
28 | }
29 | throw new IllegalArgumentException("No two sum solution");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/104. Maximum Depth of Binary Tree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Given a binary tree, find its maximum depth.
3 | *
4 | * The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
5 | *
6 | * Note: A leaf is a node with no children.
7 | *
8 | * Example:
9 | *
10 | * Given binary tree [3,9,20,null,null,15,7],
11 | *
12 | * 3
13 | * / \
14 | * 9 20
15 | * / \
16 | * 15 7
17 | * return its depth = 3.
18 | *
19 | */
20 |
21 | /**
22 | * Definition for a binary tree node.
23 | * public class TreeNode {
24 | * int val;
25 | * TreeNode left;
26 | * TreeNode right;
27 | * TreeNode(int x) { val = x; }
28 | * }
29 | */
30 | class Solution {
31 |
32 | public int maxDepth(TreeNode root) {
33 | if (root == null) {
34 | return 0;
35 | }
36 |
37 | int left = maxDepth(root.left);// This will give me the left "subtree", not just the left node value
38 | int right = maxDepth(root.right); //This will give me the right "subtree", not just the right node value
39 |
40 | return Math.max(left, right) + 1;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/112. Path Sum.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
4 | *
5 | * Note: A leaf is a node with no children.
6 | *
7 | * Example:
8 | *
9 | * Given the below binary tree and sum = 22,
10 | *
11 | * 5
12 | * / \
13 | * 4 8
14 | * / / \
15 | * 11 13 4
16 | * / \ \
17 | * 7 2 1
18 | * return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22
19 | *
20 | */
21 |
22 | /**
23 | * Definition for a binary tree node.
24 | * public class TreeNode {
25 | * int val;
26 | * TreeNode left;
27 | * TreeNode right;
28 | * TreeNode(int x) { val = x; }
29 | * }
30 | */
31 | class Solution {
32 |
33 | public boolean hasPathSum(TreeNode root, int sum) {
34 | if (root == null) {
35 | return false;
36 | }
37 |
38 | if (root.left == null && root.right == null && sum - root.val == 0) {
39 | return true;
40 | }
41 |
42 | return (hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val));
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/120. Triangle.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.
4 |
5 | For example, given the following triangle
6 |
7 | [
8 | [2],
9 | [3,4],
10 | [6,5,7],
11 | [4,1,8,3]
12 | ]
13 | The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).
14 |
15 | Note:
16 |
17 | Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.
18 |
19 | */
20 |
21 | class Solution {
22 | public int minimumTotal(List> triangle) {
23 | int size = triangle.size();
24 | int[] results = new int[size+1];
25 |
26 | for(int i=size-1; i>=0; i--) {
27 | List tmp = triangle.get(i);
28 |
29 | for(int j=0; j map = new HashMap();
24 |
25 | for (int i : nums) {
26 | if (map.containsKey(i)) {
27 | map.put(i, map.get(i) + 1);
28 | } else {
29 | map.put(i, 1);
30 | }
31 | }
32 |
33 | for (Map.Entry entry : map.entrySet()) {
34 | if (entry.getValue() == 1) {
35 | return entry.getKey();
36 |
37 | }
38 |
39 | }
40 | return 0;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/14. Longest Common Prefix.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Write a function to find the longest common prefix string amongst an array of strings.
3 | *
4 | * If there is no common prefix, return an empty string "".
5 | *
6 | * Example 1:
7 | *
8 | * Input: ["flower","flow","flight"]
9 | * Output: "fl"
10 | * Example 2:
11 | *
12 | * Input: ["dog","racecar","car"]
13 | * Output: ""
14 | * Explanation: There is no common prefix among the input strings.
15 | * Note:
16 | *
17 | * All given inputs are in lowercase letters a-z.
18 | */
19 |
20 | class Solution {
21 |
22 | public String longestCommonPrefix(String[] strs) {
23 | if (strs.length == 0) {
24 | return "";
25 | }
26 | String prefix = strs[0];
27 | for (int i = 1; i < strs.length; i++) {
28 | while (strs[i].indexOf(prefix) != 0) {
29 | prefix = prefix.substring(0, prefix.length() - 1);
30 | if (prefix.isEmpty()) {
31 | return "";
32 | }
33 | }
34 | }
35 | return prefix;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/144. Binary Tree Preorder Traversal.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Given a binary tree, return the preorder traversal of its nodes' values.
3 | *
4 | * Example:
5 | *
6 | * Input: [1,null,2,3]
7 | * 1
8 | * \
9 | * 2
10 | * /
11 | * 3
12 | *
13 | * Output: [1,2,3]
14 | *
15 | */
16 |
17 | class Solution {
18 |
19 | public List preorderTraversal(TreeNode root) {
20 | List pre = new LinkedList();
21 | if (root == null) {
22 | return pre;
23 | }
24 | pre.add(root.val);
25 | pre.addAll(preorderTraversal(root.left));
26 | pre.addAll(preorderTraversal(root.right));
27 | return pre;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/145. Binary Tree Postorder Traversal.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a binary tree, return the postorder traversal of its nodes' values.
4 | *
5 | * Example:
6 | *
7 | * Input: [1,null,2,3]
8 | * 1
9 | * \
10 | * 2
11 | * /
12 | * 3
13 | *
14 | * Output: [3,2,1]
15 | *
16 | */
17 |
18 | class Solution {
19 |
20 | public List postorderTraversal(TreeNode root) {
21 | List result = new ArrayList();
22 | if (root != null) {
23 | result.addAll(postorderTraversal(root.left));
24 |
25 | result.addAll(postorderTraversal(root.right));
26 | result.add(root.val);
27 | }
28 | return result;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/175. Combine Two Tables.java:
--------------------------------------------------------------------------------
1 | /*
2 | Table: Person
3 |
4 | +-------------+---------+
5 | | Column Name | Type |
6 | +-------------+---------+
7 | | PersonId | int |
8 | | FirstName | varchar |
9 | | LastName | varchar |
10 | +-------------+---------+
11 | PersonId is the primary key column for this table.
12 | Table: Address
13 |
14 | +-------------+---------+
15 | | Column Name | Type |
16 | +-------------+---------+
17 | | AddressId | int |
18 | | PersonId | int |
19 | | City | varchar |
20 | | State | varchar |
21 | +-------------+---------+
22 | AddressId is the primary key column for this table.
23 |
24 |
25 | Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:
26 |
27 | FirstName, LastName, City, State
28 |
29 | */
30 |
31 | // SQL Query
32 |
33 | select Person.FirstName, Person.LastName, Address.City, Address.State
34 | from Person left Join Address on Person.PersonId = Address.PersonId
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/187. Repeated DNA Sequences.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.
4 | *
5 | * Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.
6 | *
7 | * Example:
8 | *
9 | * Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
10 | *
11 | * Output: ["AAAAACCCCC", "CCCCCAAAAA"]
12 | *
13 | */
14 |
15 | class Solution {
16 |
17 | public List findRepeatedDnaSequences(String s) {
18 | HashSet seen = new HashSet<>();
19 | HashSet repeated = new HashSet<>();
20 |
21 | for (int i = 0; i + 9 < s.length(); i++) {
22 | String temp = s.substring(i, i + 10);
23 | if (seen.contains(temp)) {
24 | repeated.add(temp);
25 | } else {
26 | seen.add(temp);
27 | }
28 | }
29 |
30 | return new ArrayList(repeated);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/193. Valid Phone Numbers.java:
--------------------------------------------------------------------------------
1 | awk '/^(\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$/' file.txt
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/2. Add Two Numbers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
3 | *
4 | * You may assume the two numbers do not contain any leading zero, except the number 0 itself.
5 | *
6 | * Example:
7 | *
8 | * Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
9 | * Output: 7 -> 0 -> 8
10 | * Explanation: 342 + 465 = 807.
11 | */
12 |
13 | class Solution {
14 |
15 | public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
16 | int carry = 0;
17 | ListNode p, dummy = new ListNode(0);
18 | p = dummy;
19 | while (l1 != null || l2 != null || carry != 0) {
20 | if (l1 != null) {
21 | carry += l1.val;
22 | l1 = l1.next;
23 | }
24 | if (l2 != null) {
25 | carry += l2.val;
26 | l2 = l2.next;
27 | }
28 | p.next = new ListNode(carry % 10);
29 | carry /= 10;
30 | p = p.next;
31 | }
32 | return dummy.next;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/202. Happy Number.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Write an algorithm to determine if a number is "happy".
4 | *
5 | * A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.
6 | *
7 | * Example:
8 | * Input: 19
9 | * Output: true
10 | * Explanation:
11 | * 12 + 92 = 82
12 | * 82 + 22 = 68
13 | * 62 + 82 = 100
14 | * 12 + 02 + 02 = 1
15 | *
16 | */
17 |
18 | class Solution {
19 |
20 | public boolean isHappy(int n) {
21 | if (n <= 0) {
22 | return false;
23 | }
24 |
25 | while (n >= 10) {
26 | int sum = 0;
27 | while (n != 0) {
28 | sum += (n % 10) * (n % 10);
29 | n /= 10;
30 | }
31 | n = sum;
32 | }
33 | return n == 1 || n == 7;
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/203. Remove Linked List Elements.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Remove all elements from a linked list of integers that have value val.
4 | *
5 | * Example:
6 | *
7 | * Input: 1->2->6->3->4->5->6, val = 6
8 | * Output: 1->2->3->4->5
9 | *
10 | */
11 |
12 | /**
13 | * Definition for singly-linked list.
14 | * public class ListNode {
15 | * int val;
16 | * ListNode next;
17 | * ListNode(int x) { val = x; }
18 | * }
19 | */
20 | class Solution {
21 |
22 | public ListNode removeElements(ListNode head, int val) {
23 | ListNode helper = new ListNode(0);
24 | helper.next = head;
25 | ListNode p = helper;
26 |
27 | while (p.next != null) {
28 | if (p.next.val == val) {
29 | ListNode next = p.next;
30 | p.next = next.next;
31 | } else {
32 | p = p.next;
33 | }
34 | }
35 |
36 | return helper.next;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/205. Isomorphic Strings.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given two strings s and t, determine if they are isomorphic.
4 | *
5 | * Two strings are isomorphic if the characters in s can be replaced to get t.
6 | *
7 | * 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.
8 | *
9 | * Example 1:
10 | *
11 | * Input: s = "egg", t = "add"
12 | * Output: true
13 | * Example 2:
14 | *
15 | * Input: s = "foo", t = "bar"
16 | * Output: false
17 | * Example 3:
18 | *
19 | * Input: s = "paper", t = "title"
20 | * Output: true
21 | * Note:
22 | * You may assume both s and t have the same length.
23 | *
24 | */
25 |
26 | class Solution {
27 |
28 | public boolean isIsomorphic(String s1, String s2) {
29 | Map m1 = new HashMap<>();
30 | Map m2 = new HashMap<>();
31 |
32 | for (Integer i = 0; i < s1.length(); i++) {
33 |
34 | if (m1.put(s1.charAt(i), i) != m2.put(s2.charAt(i), i)) {
35 | return false;
36 | }
37 | }
38 | return true;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/215. Kth Largest Element in an Array.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.
4 | *
5 | * Example 1:
6 | *
7 | * Input: [3,2,1,5,6,4] and k = 2
8 | * Output: 5
9 | * Example 2:
10 | *
11 | * Input: [3,2,3,1,2,4,5,5,6] and k = 4
12 | * Output: 4
13 | * Note:
14 | * You may assume k is always valid, 1 ≤ k ≤ array's length.
15 | *
16 | */
17 |
18 | class Solution {
19 |
20 | public int findKthLargest(int[] nums, int k) {
21 | PriorityQueue queue = new PriorityQueue();
22 |
23 | for (int n : nums) {
24 | queue.offer(n);
25 |
26 | if (queue.size() > k) {
27 | queue.poll();
28 | }
29 | }
30 | return queue.peek();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/217. Contains Duplicate.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given an array of integers, find if the array contains any duplicates.
4 | *
5 | * Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
6 | *
7 | * Example 1:
8 | *
9 | * Input: [1,2,3,1]
10 | * Output: true
11 | * Example 2:
12 | *
13 | * Input: [1,2,3,4]
14 | * Output: false
15 | * Example 3:
16 | *
17 | * Input: [1,1,1,3,3,4,3,2,4,2]
18 | * Output: true
19 | *
20 | */
21 |
22 | class Solution {
23 |
24 | public boolean containsDuplicate(int[] nums) {
25 |
26 | Set set = new HashSet();
27 |
28 | for (int i : nums) {
29 | if (set.contains(i)) {
30 | return true;
31 | } else {
32 | set.add(i);
33 | }
34 | }
35 |
36 | return false;
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/219. Contains Duplicate II.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.
4 | *
5 | * Example 1:
6 | *
7 | * Input: nums = [1,2,3,1], k = 3
8 | * Output: true
9 | * Example 2:
10 | *
11 | * Input: nums = [1,0,1,1], k = 1
12 | * Output: true
13 | * Example 3:
14 | *
15 | * Input: nums = [1,2,3,1,2,3], k = 2
16 | * Output: false
17 | *
18 | */
19 |
20 | class Solution {
21 |
22 | public boolean containsNearbyDuplicate(int[] nums, int k) {
23 | Set set = new HashSet<>();
24 | for (int i = 0; i < nums.length; ++i) {
25 | if (set.contains(nums[i])) {
26 | return true;
27 | }
28 | set.add(nums[i]);
29 | if (set.size() > k) {
30 | set.remove(nums[i - k]);
31 | }
32 | }
33 | return false;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/226. Invert Binary Tree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Invert a binary tree.
3 | *
4 | * Example:
5 | *
6 | * Input:
7 | *
8 | * 4
9 | * / \
10 | * 2 7
11 | * / \ / \
12 | * 1 3 6 9
13 | * Output:
14 | *
15 | * 4
16 | * / \
17 | * 7 2
18 | * / \ / \
19 | * 9 6 3 1
20 | * Trivia:
21 | * This problem was inspired by this original tweet by Max Howell:
22 | *
23 | * Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so f*** off.
24 | *
25 | */
26 |
27 | class Solution {
28 |
29 | public TreeNode invertTree(TreeNode root) {
30 | if (root == null) {
31 | return null;
32 | }
33 | TreeNode right = invertTree(root.right);
34 | TreeNode left = invertTree(root.left);
35 | root.left = right;
36 | root.right = left;
37 | return root;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/231. Power of Two.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given an integer, write a function to determine if it is a power of two.
4 | *
5 | * Example 1:
6 | *
7 | * Input: 1
8 | * Output: true
9 | * Explanation: 20 = 1
10 | * Example 2:
11 | *
12 | * Input: 16
13 | * Output: true
14 | * Explanation: 24 = 16
15 | * Example 3:
16 | *
17 | * Input: 218
18 | * Output: false
19 | *
20 | */
21 |
22 | class Solution {
23 |
24 | public boolean isPowerOfTwo(int n) {
25 | /*
26 | * If n is the power of two:
27 | *
28 | * n = 2 ^ 0 = 1 = 0b0000...00000001, and (n - 1) = 0 = 0b0000...0000. n
29 | * = 2 ^ 1 = 2 = 0b0000...00000010, and (n - 1) = 1 = 0b0000...0001. n =
30 | * 2 ^ 2 = 4 = 0b0000...00000100, and (n - 1) = 3 = 0b0000...0011. n = 2
31 | * ^ 3 = 8 = 0b0000...00001000, and (n - 1) = 7 = 0b0000...0111. we have
32 | * n & (n-1) == 0b0000...0000 == 0
33 | *
34 | * Otherwise, n & (n-1) != 0.
35 | *
36 | * For example, n =14 = 0b0000...1110, and (n - 1) = 13 = 0b0000...1101.
37 | */
38 | return n > 0 && ((n & (n - 1)) == 0);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/237. Delete Node in a Linked List.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
4 | *
5 | * Given linked list -- head = [4,5,1,9], which looks like following:
6 | *
7 | *
8 | * Example 1:
9 | *
10 | * Input: head = [4,5,1,9], node = 5
11 | * Output: [4,1,9]
12 | * Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.
13 | * Example 2:
14 | *
15 | * Input: head = [4,5,1,9], node = 1
16 | * Output: [4,5,9]
17 | * Explanation: You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function.
18 | *
19 | *
20 | * Note:
21 | *
22 | * The linked list will have at least two elements.
23 | * All of the nodes' values will be unique.
24 | * The given node will not be the tail and it will always be a valid node of the linked list.
25 | * Do not return anything from your function.
26 | *
27 | */
28 |
29 | class Solution {
30 |
31 | public void deleteNode(ListNode node) {
32 | node.val = node.next.val;
33 | node.next = node.next.next;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/257. Binary Tree Paths.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a binary tree, return all root-to-leaf paths.
4 | *
5 | * Note: A leaf is a node with no children.
6 | *
7 | * Example:
8 | *
9 | * Input:
10 | *
11 | * 1
12 | * / \
13 | * 2 3
14 | * \
15 | * 5
16 | *
17 | * Output: ["1->2->5", "1->3"]
18 | *
19 | * Explanation: All root-to-leaf paths are: 1->2->5, 1->3
20 | *
21 | */
22 |
23 | class Solution {
24 |
25 | public List binaryTreePaths(TreeNode root) {
26 | ArrayList res = new ArrayList();
27 | helper(root, "", res);
28 | return res;
29 | }
30 |
31 | void helper(TreeNode root, String path, ArrayList res) {
32 | if (root == null) {
33 | return;
34 | }
35 | if (root.left == null && root.right == null) {
36 | res.add(path + root.val);
37 | }
38 | helper(root.left, path + root.val + "->", res);
39 | helper(root.right, path + root.val + "->", res);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/258. Add Digits.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
4 | *
5 | * Example:
6 | *
7 | * Input: 38
8 | * Output: 2
9 | * Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2.
10 | * Since 2 has only one digit, return it.
11 | * Follow up:
12 | * Could you do it without any loop/recursion in O(1) runtime?
13 | *
14 | */
15 |
16 | class Solution {
17 |
18 | public int addDigits(int num) {
19 | int res = num % 9;
20 | return (res != 0 || num == 0) ? res : 9;
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/268. Missing Number.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.
4 | *
5 | * Example 1:
6 | *
7 | * Input: [3,0,1]
8 | * Output: 2
9 | * Example 2:
10 | *
11 | * Input: [9,6,4,2,3,5,7,0,1]
12 | * Output: 8
13 | * Note:
14 | * Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?
15 | *
16 | */
17 |
18 | class Solution {
19 |
20 | public int missingNumber(int[] nums) {
21 | int res = nums.length;
22 | for (int i = 0; i < nums.length; i++) {
23 | res ^= i;
24 | res ^= nums[i];
25 | }
26 | return res;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/279. Perfect Squares.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.
4 | *
5 | * Example 1:
6 | *
7 | * Input: n = 12
8 | * Output: 3
9 | * Explanation: 12 = 4 + 4 + 4.
10 | * Example 2:
11 | *
12 | * Input: n = 13
13 | * Output: 2
14 | * Explanation: 13 = 4 + 9.
15 | *
16 | */
17 |
18 | class Solution {
19 |
20 | public int numSquares(int n) {
21 | int[] DP = new int[n + 1];
22 | for (int i = 1; i <= n; i++) {
23 | int min = Integer.MAX_VALUE;
24 | for (int j = 1; j * j <= i; j++) {
25 | min = Math.min(min, DP[i - j * j] + 1);
26 | }
27 | DP[i] = min;
28 | }
29 | return DP[n];
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/28. Implement strStr().java:
--------------------------------------------------------------------------------
1 | /*
2 | * Implement strStr().
3 | *
4 | * Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
5 | *
6 | * Example 1:
7 | *
8 | * Input: haystack = "hello", needle = "ll"
9 | * Output: 2
10 | * Example 2:
11 | *
12 | * Input: haystack = "aaaaa", needle = "bba"
13 | * Output: -1
14 | * Clarification:
15 | *
16 | * What should we return when needle is an empty string? This is a great question to ask during an interview.
17 | *
18 | * For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strstr() and Java's indexOf().
19 | *
20 | */
21 |
22 | class Solution {
23 |
24 | public int strStr(String haystack, String needle) {
25 | return haystack.indexOf(needle);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/283. Move Zeroes.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
4 | *
5 | * Example:
6 | *
7 | * Input: [0,1,0,3,12]
8 | * Output: [1,3,12,0,0]
9 | * Note:
10 | *
11 | * You must do this in-place without making a copy of the array.
12 | * Minimize the total number of operations.
13 | *
14 | */
15 |
16 | class Solution {
17 |
18 | public void moveZeroes(int[] nums) {
19 | int i = 0;
20 | int j = 0;
21 |
22 | while (j < nums.length) {
23 | if (nums[j] == 0) {
24 | j++;
25 | } else {
26 | nums[i] = nums[j];
27 | i++;
28 | j++;
29 | }
30 | }
31 |
32 | while (i < nums.length) {
33 | nums[i] = 0;
34 | i++;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/303. Range Sum Query - Immutable.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.
4 | *
5 | * Example:
6 | * Given nums = [-2, 0, 3, -5, 2, -1]
7 | *
8 | * sumRange(0, 2) -> 1
9 | * sumRange(2, 5) -> -1
10 | * sumRange(0, 5) -> -3
11 | * Note:
12 | * You may assume that the array does not change.
13 | * There are many calls to sumRange function.
14 | *
15 | */
16 |
17 | class NumArray {
18 |
19 | private int[] data;
20 |
21 | public NumArray(int[] nums) {
22 | data = nums;
23 | }
24 |
25 | public int sumRange(int i, int j) {
26 | int sum = 0;
27 | while (i <= j) {
28 | sum += data[i];
29 | i++;
30 | }
31 | return sum;
32 | }
33 | }
34 |
35 | /**
36 | * Your NumArray object will be instantiated and called as such:
37 | * NumArray obj = new NumArray(nums);
38 | * int param_1 = obj.sumRange(i,j);
39 | */
40 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/349. Intersection of Two Arrays.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given two arrays, write a function to compute their intersection.
4 | *
5 | * Example 1:
6 | *
7 | * Input: nums1 = [1,2,2,1], nums2 = [2,2]
8 | * Output: [2]
9 | * Example 2:
10 | *
11 | * Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
12 | * Output: [9,4]
13 | * Note:
14 | *
15 | * Each element in the result must be unique.
16 | * The result can be in any order.
17 | *
18 | */
19 |
20 | class Solution {
21 |
22 | public int[] intersection(int[] nums1, int[] nums2) {
23 | HashSet set1 = new HashSet();
24 | for (int i : nums1) {
25 | set1.add(i);
26 | }
27 |
28 | HashSet set2 = new HashSet();
29 | for (int i : nums2) {
30 | if (set1.contains(i)) {
31 | set2.add(i);
32 | }
33 | }
34 |
35 | int[] result = new int[set2.size()];
36 | int i = 0;
37 | for (int n : set2) {
38 | result[i++] = n;
39 | }
40 |
41 | return result;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/35. Search Insert Position.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 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.
3 | *
4 | * You may assume no duplicates in the array.
5 | *
6 | * Example 1:
7 | *
8 | * Input: [1,3,5,6], 5
9 | * Output: 2
10 | * Example 2:
11 | *
12 | * Input: [1,3,5,6], 2
13 | * Output: 1
14 | * Example 3:
15 | *
16 | * Input: [1,3,5,6], 7
17 | * Output: 4
18 | * Example 4:
19 | *
20 | * Input: [1,3,5,6], 0
21 | * Output: 0
22 | *
23 | */
24 |
25 | class Solution {
26 |
27 | public static int searchInsert(int[] nums, int target) {
28 |
29 | int position = -1;
30 |
31 | for (int i = 0; i < nums.length; i++) {
32 | if (target == nums[i]) {
33 | position = i;
34 | break;
35 | } else if (target > nums[i]) {
36 | continue;
37 | } else {
38 | position = i;
39 | break;
40 | }
41 | }
42 |
43 | if (position == -1) {
44 | position = nums.length;
45 | }
46 |
47 | return position;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/367. Valid Perfect Square.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a positive integer num, write a function which returns True if num is a perfect square else False.
4 | *
5 | * Note: Do not use any built-in library function such as sqrt.
6 | *
7 | * Example 1:
8 | *
9 | * Input: 16
10 | * Output: true
11 | * Example 2:
12 | *
13 | * Input: 14
14 | * Output: false
15 | *
16 | */
17 |
18 | class Solution {
19 |
20 | public boolean isPerfectSquare(int n) {
21 | long sum = 0;
22 | for (int i = 1; sum < n; i = i + 2) {
23 | sum = sum + i;
24 | if (sum == n) {
25 | return true;
26 | }
27 | }
28 | return false;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/371. Sum of Two Integers.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.
4 | *
5 | * Example 1:
6 | *
7 | * Input: a = 1, b = 2
8 | * Output: 3
9 | * Example 2:
10 | *
11 | * Input: a = -2, b = 3
12 | * Output: 1
13 | *
14 | */
15 |
16 | class Solution {
17 |
18 | public int getSum(int a, int b) {
19 | if (a == 0) {
20 | return b;
21 | }
22 | if (b == 0) {
23 | return a;
24 | }
25 |
26 | while (b != 0) {
27 | int carry = a & b;
28 | a = a ^ b;
29 | b = carry << 1;
30 | }
31 |
32 | return a;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/378. Kth Smallest Element in a Sorted Matrix.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.
4 | *
5 | * Note that it is the kth smallest element in the sorted order, not the kth distinct element.
6 | *
7 | * Example:
8 | *
9 | * matrix = [
10 | * [ 1, 5, 9],
11 | * [10, 11, 13],
12 | * [12, 13, 15]
13 | * ],
14 | * k = 8,
15 | *
16 | * return 13.
17 | *
18 | */
19 |
20 | class Solution {
21 |
22 | public int kthSmallest(int[][] matrix, int k) {
23 | PriorityQueue minHeap = new PriorityQueue(k, (a, b) -> (a - b));
24 |
25 | for (int i = 0; i < matrix.length; i++) {
26 | for (int j = 0; j < matrix[0].length; j++) {
27 | minHeap.offer(matrix[i][j]);
28 | }
29 | }
30 |
31 | int result = 0;
32 | while (k > 0) {
33 | result = minHeap.poll();
34 | k--;
35 | }
36 | return result;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/383. Ransom Note.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; otherwise, it will return false.
4 | *
5 | * Each letter in the magazine string can only be used once in your ransom note.
6 | *
7 | * Note:
8 | * You may assume that both strings contain only lowercase letters.
9 | *
10 | * canConstruct("a", "b") -> false
11 | * canConstruct("aa", "ab") -> false
12 | * canConstruct("aa", "aab") -> true
13 | *
14 | */
15 |
16 | class Solution {
17 |
18 | public boolean canConstruct(String ransomNote, String magazine) {
19 | int[] cnt = new int[26];
20 | for (char c : magazine.toCharArray()) {
21 | cnt[c - 'a']++;
22 | }
23 |
24 | for (char c : ransomNote.toCharArray()) {
25 | if (--cnt[c - 'a'] < 0) {
26 | return false;
27 | }
28 | }
29 | return true;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/387. First Unique Character in a String.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.
4 | *
5 | * Examples:
6 | *
7 | * s = "leetcode"
8 | * return 0.
9 | *
10 | * s = "loveleetcode",
11 | * return 2.
12 | * Note: You may assume the string contain only lowercase letters.
13 | *
14 | *
15 | */
16 |
17 | class Solution {
18 |
19 | public int firstUniqChar(String s) {
20 | HashMap map = new HashMap<>();
21 |
22 | for (char c : s.toCharArray()) {
23 | map.put(c, map.getOrDefault(c, 0) + 1);
24 | }
25 |
26 | for (int i = 0; i < s.length(); i++) {
27 | if (map.get(s.charAt(i)) == 1) {
28 | return i;
29 | }
30 | }
31 |
32 | return -1;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/389. Find the Difference.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given two strings s and t which consist of only lowercase letters.
4 | *
5 | * String t is generated by random shuffling string s and then add one more letter at a random position.
6 | *
7 | * Find the letter that was added in t.
8 | *
9 | * Example:
10 | *
11 | * Input:
12 | * s = "abcd"
13 | * t = "abcde"
14 | *
15 | * Output:
16 | * e
17 | *
18 | * Explanation:
19 | * 'e' is the letter that was added.
20 | *
21 | */
22 |
23 | public class Solution {
24 |
25 | public char findTheDifference(String s, String t) {
26 | char c = 0;
27 | for (int i = 0; i < s.length(); i++) {
28 | c ^= s.charAt(i);
29 | }
30 | for (int i = 0; i < t.length(); i++) {
31 | c ^= t.charAt(i);
32 | }
33 | return c;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/412. Fizz Buzz.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Write a program that outputs the string representation of numbers from 1 to n.
4 | *
5 | * But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.
6 | *
7 | * Example:
8 | *
9 | * n = 15,
10 | *
11 | * Return:
12 | * [
13 | * "1",
14 | * "2",
15 | * "Fizz",
16 | * "4",
17 | * "Buzz",
18 | * "Fizz",
19 | * "7",
20 | * "8",
21 | * "Fizz",
22 | * "Buzz",
23 | * "11",
24 | * "Fizz",
25 | * "13",
26 | * "14",
27 | * "FizzBuzz"
28 | * ]
29 | *
30 | */
31 |
32 | class Solution {
33 |
34 | public List fizzBuzz(int n) {
35 | List list = new ArrayList<>();
36 | for (int i = 1; i <= n; i++) {
37 | if (i % 3 == 0 && i % 5 == 0) {
38 | list.add("FizzBuzz");
39 | } else if (i % 3 == 0) {
40 | list.add("Fizz");
41 | } else if (i % 5 == 0) {
42 | list.add("Buzz");
43 | } else {
44 | list.add(String.valueOf(i));
45 | }
46 | }
47 | return list;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/434. Number of Segments in a String.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.
4 | *
5 | * Please note that the string does not contain any non-printable characters.
6 | *
7 | * Example:
8 | *
9 | * Input: "Hello, my name is John"
10 | * Output: 5
11 | *
12 | */
13 |
14 | class Solution {
15 |
16 | public int countSegments(String s) {
17 | s = s.trim();
18 |
19 | if (s.length() == 0) //everything was just space then return 0
20 | {
21 | return 0;
22 | }
23 |
24 | return s.split("\\s+").length;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/448. Find All Numbers Disappeared in an Array.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
4 | *
5 | * Find all the elements of [1, n] inclusive that do not appear in this array.
6 | *
7 | * Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.
8 | *
9 | * Example:
10 | *
11 | * Input:
12 | * [4,3,2,7,8,2,3,1]
13 | *
14 | * Output:
15 | * [5,6]
16 | *
17 | */
18 |
19 | class Solution {
20 |
21 | public List findDisappearedNumbers(int[] nums) {
22 | int[] lookup = new int[nums.length + 1];
23 | for (int i = 0; i < nums.length; i++) {
24 | lookup[nums[i]]++;
25 | }
26 |
27 | ArrayList ret = new ArrayList();
28 | for (int i = 0; i < lookup.length; i++) {
29 | if (lookup[i] == 0 && i != 0) {
30 | ret.add(i);
31 | }
32 | }
33 | return ret;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/45. Jump Game II.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given an array of non-negative integers, you are initially positioned at the first index of the array.
4 | *
5 | * Each element in the array represents your maximum jump length at that position.
6 | *
7 | * Your goal is to reach the last index in the minimum number of jumps.
8 | *
9 | * Example:
10 | *
11 | * Input: [2,3,1,1,4]
12 | * Output: 2
13 | * Explanation: The minimum number of jumps to reach the last index is 2.
14 | * Jump 1 step from index 0 to 1, then 3 steps to the last index.
15 | * Note:
16 | *
17 | * You can assume that you can always reach the last index.
18 | *
19 | */
20 |
21 | class Solution {
22 |
23 | public int jump(int[] A) {
24 | int step_count = 0;
25 | int last_jump_max = 0;
26 | int current_jump_max = 0;
27 | for (int i = 0; i < A.length - 1; i++) {
28 | current_jump_max = Math.max(current_jump_max, i + A[i]);
29 | if (i == last_jump_max) {
30 | step_count++;
31 | last_jump_max = current_jump_max;
32 | }
33 | }
34 | return step_count;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/459. Repeated Substring Pattern.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.
4 | *
5 | * Example 1:
6 | *
7 | * Input: "abab"
8 | * Output: True
9 | * Explanation: It's the substring "ab" twice.
10 | * Example 2:
11 | *
12 | * Input: "aba"
13 | * Output: False
14 | * Example 3:
15 | *
16 | * Input: "abcabcabcabc"
17 | * Output: True
18 | * Explanation: It's the substring "abc" four times. (And the substring "abcabc" twice.)
19 | *
20 | */
21 |
22 | class Solution {
23 |
24 | public boolean repeatedSubstringPattern(String str) {
25 | String s = str + str;
26 | return s.substring(1, s.length() - 1).contains(str);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/461. Hamming Distance.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
4 |
5 | Given two integers x and y, calculate the Hamming distance.
6 |
7 | Note:
8 | 0 ≤ x, y < 231.
9 |
10 | Example:
11 |
12 | Input: x = 1, y = 4
13 |
14 | Output: 2
15 |
16 | Explanation:
17 | 1 (0 0 0 1)
18 | 4 (0 1 0 0)
19 | ↑ ↑
20 |
21 | The above arrows point to positions where the corresponding bits are different.
22 |
23 | */
24 |
25 | public class Solution {
26 | public int hammingDistance(int x, int y)
27 | {
28 |
29 | int n = x ^ y;
30 |
31 | int count = 0;
32 | while (n != 0) {
33 | count++;
34 | n = n & (n - 1);
35 | }
36 | return count;
37 | }
38 | }
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/476. Number Complement.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.
4 | *
5 | * Note:
6 | * The given integer is guaranteed to fit within the range of a 32-bit signed integer.
7 | * You could assume no leading zero bit in the integer’s binary representation.
8 | * Example 1:
9 | * Input: 5
10 | * Output: 2
11 | * Explanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.
12 | * Example 2:
13 | * Input: 1
14 | * Output: 0
15 | * Explanation: The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.
16 | *
17 | */
18 |
19 | public class Solution {
20 |
21 | public int findComplement(int num) {
22 | int i = 0;
23 | int j = 0;
24 |
25 | while (i < num) {
26 | i += Math.pow(2, j);
27 | j++;
28 | }
29 |
30 | return i - num;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/485. Max Consecutive Ones.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a binary array, find the maximum number of consecutive 1s in this array.
4 | *
5 | * Example 1:
6 | * Input: [1,1,0,1,1,1]
7 | * Output: 3
8 | * Explanation: The first two digits or the last three digits are consecutive 1s.
9 | * The maximum number of consecutive 1s is 3.
10 | * Note:
11 | *
12 | * The input array will only contain 0 and 1.
13 | * The length of input array is a positive integer and will not exceed 10,000
14 | *
15 | */
16 |
17 | class Solution {
18 |
19 | public int findMaxConsecutiveOnes(int[] num) {
20 | int result = 0;
21 | int count = 0;
22 | int max = -1;
23 | int temp = -1;
24 | for (int i = 0; i < num.length; i++) {
25 | if (num[i] == 1) {
26 | count++;
27 | temp = count;
28 | } else {
29 | temp = count;
30 | if (num[i] == 0) {
31 | count = 0;
32 | }
33 | }
34 | if (max < temp) {
35 | max = temp;
36 | }
37 | }
38 |
39 | return max;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/49. Group Anagrams.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Given an array of strings, group anagrams together.
3 | *
4 | * Example:
5 | *
6 | * Input: ["eat", "tea", "tan", "ate", "nat", "bat"],
7 | * Output:
8 | * [
9 | * ["ate","eat","tea"],
10 | * ["nat","tan"],
11 | * ["bat"]
12 | * ]
13 | * Note:
14 | *
15 | * All inputs will be in lowercase.
16 | * The order of your output does not matter.
17 | *
18 | */
19 |
20 | class Solution {
21 |
22 | public List> groupAnagrams(String[] strs) {
23 | if (strs.length == 0) {
24 | return new ArrayList();
25 | }
26 | Map ans = new HashMap();
27 | for (String s : strs) {
28 | char[] ca = s.toCharArray();
29 | Arrays.sort(ca);
30 | String key = String.valueOf(ca);
31 | if (!ans.containsKey(key)) {
32 | ans.put(key, new ArrayList());
33 | }
34 | ans.get(key).add(s);
35 | }
36 | return new ArrayList(ans.values());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/50. Pow(x, n).java:
--------------------------------------------------------------------------------
1 | /*
2 | * Implement pow(x, n), which calculates x raised to the power n (xn).
3 | *
4 | * Example 1:
5 | *
6 | * Input: 2.00000, 10
7 | * Output: 1024.00000
8 | * Example 2:
9 | *
10 | * Input: 2.10000, 3
11 | * Output: 9.26100
12 | * Example 3:
13 | *
14 | * Input: 2.00000, -2
15 | * Output: 0.25000
16 | * Explanation: 2-2 = 1/22 = 1/4 = 0.25
17 | * Note:
18 | *
19 | * -100.0 < x < 100.0
20 | * n is a 32-bit signed integer, within the range [−231, 231 − 1]
21 | *
22 | */
23 |
24 | class Solution {
25 |
26 | private double fastPow(double x, long n) {
27 | if (n == 0) {
28 | return 1.0;
29 | }
30 |
31 | double half = fastPow(x, n / 2);
32 |
33 | if (n % 2 == 0) {
34 | return half * half;
35 | } else {
36 | return half * half * x;
37 | }
38 | }
39 |
40 | public double myPow(double x, int n) {
41 | long N = n;
42 | if (N < 0) {
43 | x = 1 / x;
44 | N = -N;
45 | }
46 |
47 | return fastPow(x, N);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/509. Fibonacci Number.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,
4 | *
5 | * F(0) = 0, F(1) = 1
6 | * F(N) = F(N - 1) + F(N - 2), for N > 1.
7 | * Given N, calculate F(N).
8 | *
9 | *
10 | *
11 | * Example 1:
12 | *
13 | * Input: 2
14 | * Output: 1
15 | * Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
16 | * Example 2:
17 | *
18 | * Input: 3
19 | * Output: 2
20 | * Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
21 | * Example 3:
22 | *
23 | * Input: 4
24 | * Output: 3
25 | * Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.
26 | *
27 | */
28 |
29 | class Solution {
30 |
31 | public int fib(int N) {
32 | if (N <= 1) {
33 | return N;
34 | } else {
35 | return fib(N - 1) + fib(N - 2);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/513. Find Bottom Left Tree Value.java:
--------------------------------------------------------------------------------
1 | /*
2 | Given a binary tree, find the leftmost value in the last row of the tree.
3 |
4 | Example 1:
5 | Input:
6 |
7 | 2
8 | / \
9 | 1 3
10 |
11 | Output:
12 | 1
13 | Example 2:
14 | Input:
15 |
16 | 1
17 | / \
18 | 2 3
19 | / / \
20 | 4 5 6
21 | /
22 | 7
23 |
24 | Output:
25 | 7
26 | Note: You may assume the tree (i.e., the given root node) is not NULL.
27 |
28 |
29 | */
30 |
31 | class Solution {
32 |
33 | public int findBottomLeftValue(TreeNode root) {
34 | Queue queue = new LinkedList<>();
35 | queue.offer(root);
36 | TreeNode n = null;
37 |
38 | while (!queue.isEmpty()) {
39 | n = queue.poll();
40 | if (n.right != null) {
41 | queue.offer(n.right);
42 | }
43 | if (n.left != null) {
44 | queue.offer(n.left);
45 | }
46 | }
47 | return n.val;
48 |
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/520. Detect Capital.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Given a word, you need to judge whether the usage of capitals in it is right or not.
3 | *
4 | * We define the usage of capitals in a word to be right when one of the following cases holds:
5 | *
6 | * All letters in this word are capitals, like "USA".
7 | * All letters in this word are not capitals, like "leetcode".
8 | * Only the first letter in this word is capital if it has more than one letter, like "Google".
9 | * Otherwise, we define that this word doesn't use capitals in a right way.
10 | * Example 1:
11 | * Input: "USA"
12 | * Output: True
13 | * Example 2:
14 | * Input: "FlaG"
15 | * Output: False
16 | * Note: The input will be a non-empty word consisting of uppercase and lowercase latin letters.
17 | *
18 | *
19 | */
20 |
21 | class Solution {
22 |
23 | public boolean detectCapitalUse(String word) {
24 | return word.equals(word.toUpperCase())
25 | || word.equals(word.toLowerCase())
26 | || Character.isUpperCase(word.charAt(0))
27 | && word.substring(1).equals(word.substring(1).toLowerCase());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/53. Maximum Subarray.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
4 | *
5 | * Example:
6 | *
7 | * Input: [-2,1,-3,4,-1,2,1,-5,4],
8 | * Output: 6
9 | * Explanation: [4,-1,2,1] has the largest sum = 6.
10 | *
11 | */
12 |
13 | class Solution {
14 |
15 | public int maxSubArray(int[] nums) {
16 | int max_so_far = nums[0];
17 | int curr_max = nums[0];
18 |
19 | for (int i = 1; i < nums.length; i++) {
20 | curr_max = Math.max(nums[i], curr_max + nums[i]);
21 | max_so_far = Math.max(max_so_far, curr_max);
22 | }
23 | return max_so_far;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/530. Minimum Absolute Difference in BST.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.
4 |
5 | Example:
6 |
7 | Input:
8 |
9 | 1
10 | \
11 | 3
12 | /
13 | 2
14 |
15 | Output:
16 | 1
17 |
18 | Explanation:
19 | The minimum absolute difference is 1, which is the difference between 2 and 1 (or between 2 and 3).
20 |
21 |
22 | Note: There are at least two nodes in this BST.
23 |
24 |
25 | */
26 |
27 | class Solution {
28 |
29 | private int min = Integer.MAX_VALUE;
30 | private TreeNode prev = null;
31 |
32 | public int getMinimumDifference(TreeNode root) {
33 | if (root == null) {
34 | return min; //Reached the leaf node so we have got a minimum value from that subtree
35 | }
36 | getMinimumDifference(root.left);
37 |
38 | if (prev != null) {
39 | min = Math.min(min, root.val - prev.val);
40 | }
41 |
42 | prev = root;
43 | getMinimumDifference(root.right);
44 |
45 | return min;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/535. Encode and Decode TinyURL.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Note: This is a companion problem to the System Design problem: Design TinyURL.
4 | * TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk.
5 | *
6 | * Design the encode and decode methods for the TinyURL service. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL.
7 | *
8 | */
9 |
10 | public class Codec {
11 |
12 | Map map = new HashMap<>();
13 | int i = 0;
14 |
15 | public String encode(String longUrl) {
16 | map.put(i, longUrl);
17 | return "http://tinyurl.com/" + i++;
18 | }
19 |
20 | public String decode(String shortUrl) {
21 | return map.get(Integer.parseInt(shortUrl.replace("http://tinyurl.com/", "")));
22 | }
23 | }
24 |
25 | // Your Codec object will be instantiated and called as such:
26 | // Codec codec = new Codec();
27 | // codec.decode(codec.encode(url));
28 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/559. Maximum Depth of N-ary Tree.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Given a n-ary tree, find its maximum depth.
4 |
5 | The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
6 |
7 | For example, given a 3-ary tree:
8 |
9 | We should return its max depth, which is 3.
10 |
11 | Note:
12 |
13 | The depth of the tree is at most 1000.
14 | The total number of nodes is at most 5000.
15 |
16 | */
17 |
18 | /*
19 | // Definition for a Node.
20 | class Node {
21 | public int val;
22 | public List children;
23 |
24 | public Node() {}
25 |
26 | public Node(int _val,List _children) {
27 | val = _val;
28 | children = _children;
29 | }
30 | };
31 | */
32 | class Solution {
33 | public int maxDepth(Node root) {
34 | return helper(root);
35 | }
36 |
37 | public int helper(Node root) {
38 | if(root == null)
39 | return 0;
40 | if(root.children == null)
41 | return 1;
42 |
43 | int max=0;
44 | for(Node child: root.children)
45 | max = Math.max(max, helper(child));
46 |
47 | return 1+max;
48 | }
49 | }
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/560. Subarray Sum Equals K.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.
4 |
5 | Example 1:
6 | Input:nums = [1,1,1], k = 2
7 | Output: 2
8 | Note:
9 | The length of the array is in range [1, 20,000].
10 | The range of numbers in the array is [-1000, 1000] and the range of the integer k is [-1e7, 1e7].
11 |
12 | */
13 |
14 | class Solution {
15 | public int subarraySum(int[] nums, int k) {
16 | if(nums.length == 1 && k==1)
17 | return k;
18 |
19 | int result = 0;
20 | for(int i=0;i Integer.MAX_VALUE || rev < Integer.MIN_VALUE) {
29 | return 0;
30 | }
31 | }
32 | return (int) rev;
33 |
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/70. Climbing Stairs.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * You are climbing a stair case. It takes n steps to reach to the top.
4 | *
5 | * Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
6 | *
7 | * Note: Given n will be a positive integer.
8 | *
9 | * Example 1:
10 | *
11 | * Input: 2
12 | * Output: 2
13 | * Explanation: There are two ways to climb to the top.
14 | * 1. 1 step + 1 step
15 | * 2. 2 steps
16 | * Example 2:
17 | *
18 | * Input: 3
19 | * Output: 3
20 | * Explanation: There are three ways to climb to the top.
21 | * 1. 1 step + 1 step + 1 step
22 | * 2. 1 step + 2 steps
23 | * 3. 2 steps + 1 step
24 | *
25 | */
26 |
27 | class Solution {
28 |
29 | public int climbStairs(int n) {
30 | if (n == 1) {
31 | return 1;
32 | }
33 |
34 | int[] dp = new int[n + 1];
35 | dp[1] = 1;
36 | dp[2] = 2;
37 | for (int i = 3; i <= n; i++) {
38 | dp[i] = dp[i - 1] + dp[i - 2];
39 | }
40 | return dp[n];
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/709. To Lower Case.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
4 |
5 |
6 |
7 | Example 1:
8 |
9 | Input: "Hello"
10 | Output: "hello"
11 | Example 2:
12 |
13 | Input: "here"
14 | Output: "here"
15 | Example 3:
16 |
17 | Input: "LOVELY"
18 | Output: "lovely"
19 |
20 | */
21 |
22 | class Solution {
23 | public String toLowerCase(String str) {
24 | return str.toLowerCase();
25 | }
26 | }
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/739. Daily Temperatures.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.
4 |
5 | For example, given the list of temperatures T = [73, 74, 75, 71, 69, 72, 76, 73], your output should be [1, 1, 4, 2, 1, 1, 0, 0].
6 |
7 | Note: The length of temperatures will be in the range [1, 30000]. Each temperature will be an integer in the range [30, 100].
8 |
9 |
10 | */
11 |
12 | class Solution {
13 | public int[] dailyTemperatures(int[] temperatures) {
14 | int m = temperatures.length;
15 | int[] ans = new int[m];
16 | Stack stack = new Stack<>();
17 |
18 | for (int i = 0; i < m; i++)
19 | {
20 | while (!stack.empty() && temperatures[stack.peek()] < temperatures[i])
21 | ans[stack.peek()] = i - stack.pop();
22 |
23 | stack.push(i);
24 | }
25 | return ans;
26 | }
27 | }
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/746. Min Cost Climbing Stairs.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).
4 |
5 | Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1.
6 |
7 | Example 1:
8 | Input: cost = [10, 15, 20]
9 | Output: 15
10 | Explanation: Cheapest is start on cost[1], pay that cost and go to the top.
11 | Example 2:
12 | Input: cost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
13 | Output: 6
14 | Explanation: Cheapest is start on cost[0], and only step on 1s, skipping cost[3].
15 | Note:
16 | cost will have a length in the range [2, 1000].
17 | Every cost[i] will be an integer in the range [0, 999].
18 |
19 | */
20 |
21 | class Solution {
22 | public int minCostClimbingStairs(int[] cost) {
23 | for (int i = 2; i < cost.length; i++) {
24 | cost[i] += Math.min(cost[i-1], cost[i-2]);
25 | }
26 | return Math.min(cost[cost.length-1], cost[cost.length-2]);
27 | }
28 | }
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/77. Combinations.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
4 | *
5 | * Example:
6 | *
7 | * Input: n = 4, k = 2
8 | * Output:
9 | * [
10 | * [2,4],
11 | * [3,4],
12 | * [2,3],
13 | * [1,2],
14 | * [1,3],
15 | * [1,4],
16 | * ]
17 | *
18 | */
19 |
20 | class Solution {
21 |
22 | public List> combine(int n, int k) {
23 | List> result = new ArrayList<>();
24 | backtrack(result, new ArrayList(), 1, n, k);
25 | return result;
26 | }
27 |
28 | public void backtrack(List> result, ArrayList comb, int start, int n, int k) {
29 | if (k == 0) {
30 | result.add(new ArrayList<>(comb));
31 | }
32 |
33 | for (int i = start; i <= n; i++) {
34 | comb.add(i);
35 | backtrack(result, comb, i + 1, n, k - 1);
36 | comb.remove(comb.size() - 1);
37 | }
38 | }
39 | }
40 |
41 | /*
42 | * Similar approach to the Backtracking question of Subsets I & II, Combination
43 | * Sum questions https://leetcode.com/problems/subsets-ii/description/
44 | */
45 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/83. Remove Duplicates from Sorted List.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a sorted linked list, delete all duplicates such that each element appear only once.
4 | *
5 | * Example 1:
6 | *
7 | * Input: 1->1->2
8 | * Output: 1->2
9 | * Example 2:
10 | *
11 | * Input: 1->1->2->3->3
12 | * Output: 1->2->3
13 | *
14 | */
15 |
16 | /**
17 | * Definition for singly-linked list.
18 | * public class ListNode {
19 | * int val;
20 | * ListNode next;
21 | * ListNode(int x) { val = x; }
22 | * }
23 | */
24 | public class Solution {
25 |
26 | public ListNode deleteDuplicates(ListNode head) {
27 | if (head == null || head.next == null) {
28 | return head;
29 | }
30 |
31 | ListNode p = head;
32 |
33 | while (p != null && p.next != null) {
34 | if (p.val == p.next.val) {
35 | p.next = p.next.next;
36 | } else {
37 | p = p.next;
38 | }
39 | }
40 |
41 | return head;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/872. Leaf-Similar Trees.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Consider all the leaves of a binary tree. From left to right order, the values of those leaves form a leaf value sequence.
4 |
5 | For example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8).
6 |
7 | Two binary trees are considered leaf-similar if their leaf value sequence is the same.
8 |
9 | Return true if and only if the two given trees with head nodes root1 and root2 are leaf-similar.
10 |
11 | Note:
12 |
13 | Both of the given trees will have between 1 and 100 nodes
14 |
15 | */
16 |
17 | class Solution {
18 | public boolean leafSimilar(TreeNode root1, TreeNode root2) {
19 | List leaves1 = new ArrayList();
20 | List leaves2 = new ArrayList();
21 | dfs(root1, leaves1);
22 | dfs(root2, leaves2);
23 | return leaves1.equals(leaves2);
24 | }
25 |
26 | public void dfs(TreeNode node, List leafValues) {
27 | if (node != null) {
28 | if (node.left == null && node.right == null)
29 | leafValues.add(node.val);
30 | dfs(node.left, leafValues);
31 | dfs(node.right, leafValues);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/876. Middle of the Linked List.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Given a non-empty, singly linked list with head node head, return a middle node of linked list.
4 |
5 | If there are two middle nodes, return the second middle node.
6 |
7 |
8 |
9 | Example 1:
10 |
11 | Input: [1,2,3,4,5]
12 | Output: Node 3 from this list (Serialization: [3,4,5])
13 | The returned node has value 3. (The judge's serialization of this node is [3,4,5]).
14 | Note that we returned a ListNode object ans, such that:
15 | ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, and ans.next.next.next = NULL.
16 | Example 2:
17 |
18 | Input: [1,2,3,4,5,6]
19 | Output: Node 4 from this list (Serialization: [4,5,6])
20 | Since the list has two middle nodes with values 3 and 4, we return the second one.
21 |
22 |
23 | Note:
24 |
25 | The number of nodes in the given list will be between 1 and 100.
26 |
27 | */
28 |
29 | class Solution {
30 | public ListNode middleNode(ListNode head) {
31 | ListNode slow = head, fast = head;
32 | while (fast != null && fast.next != null) {
33 | slow = slow.next;
34 | fast = fast.next.next;
35 | }
36 | return slow;
37 | }
38 | }
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/88. Merge Sorted Array.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
4 | *
5 | * Note:
6 | *
7 | * The number of elements initialized in nums1 and nums2 are m and n respectively.
8 | * You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.
9 | * Example:
10 | *
11 | * Input:
12 | * nums1 = [1,2,3,0,0,0], m = 3
13 | * nums2 = [2,5,6], n = 3
14 | *
15 | * Output: [1,2,2,3,5,6]
16 | *
17 | */
18 |
19 | public class Solution {
20 |
21 | public void merge(int A[], int m, int B[], int n) {
22 |
23 | while (m > 0 && n > 0) {
24 | if (A[m - 1] > B[n - 1]) {
25 | A[m + n - 1] = A[m - 1];
26 | m--;
27 | } else {
28 | A[m + n - 1] = B[n - 1];
29 | n--;
30 | }
31 | }
32 |
33 | while (n > 0) {
34 | A[m + n - 1] = B[n - 1];
35 | n--;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/90. Subsets II.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).
4 | *
5 | * Note: The solution set must not contain duplicate subsets.
6 | *
7 | * Example:
8 | *
9 | * Input: [1,2,2]
10 | * Output:
11 | * [
12 | * [2],
13 | * [1],
14 | * [1,2,2],
15 | * [2,2],
16 | * [1,2],
17 | * []
18 | * ]
19 | *
20 | */
21 |
22 | class Solution {
23 |
24 | public List> subsetsWithDup(int[] nums) {
25 | List> list = new ArrayList<>();
26 | Arrays.sort(nums);
27 | backtrack(list, new ArrayList<>(), nums, 0);
28 | return list;
29 | }
30 |
31 | private void backtrack(List> list, List tempList, int[] nums, int start) {
32 | list.add(new ArrayList<>(tempList));
33 | for (int i = start; i < nums.length; i++) {
34 | if (i > start && nums[i] == nums[i - 1]) {
35 | continue; // skip duplicates
36 | }
37 | tempList.add(nums[i]);
38 | backtrack(list, tempList, nums, i + 1);
39 | tempList.remove(tempList.size() - 1);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/905. Sort Array By Parity.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A.
4 |
5 | You may return any answer array that satisfies this condition.
6 |
7 |
8 |
9 | Example 1:
10 |
11 | Input: [3,1,2,4]
12 | Output: [2,4,3,1]
13 | The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.
14 |
15 |
16 | Note:
17 |
18 | 1 <= A.length <= 5000
19 | 0 <= A[i] <= 5000
20 |
21 | */
22 |
23 | class Solution {
24 | public int[] sortArrayByParity(int[] A) {
25 | int[] ans = new int[A.length];
26 | int t = 0;
27 |
28 | for (int i = 0; i < A.length; ++i)
29 | if (A[i] % 2 == 0)
30 | ans[t++] = A[i];
31 |
32 | for (int i = 0; i < A.length; ++i)
33 | if (A[i] % 2 == 1)
34 | ans[t++] = A[i];
35 |
36 | return ans;
37 | }
38 | }
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/94. Binary Tree Inorder Traversal.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Given a binary tree, return the inorder traversal of its nodes' values.
4 | *
5 | * Example:
6 | *
7 | * Input: [1,null,2,3]
8 | * 1
9 | * \
10 | * 2
11 | * /
12 | * 3
13 | *
14 | * Output: [1,3,2]
15 | *
16 | */
17 |
18 | class Solution {
19 |
20 | public List inorderTraversal(TreeNode root) {
21 | List result = new ArrayList();
22 | if (root != null) {
23 | result.addAll(inorderTraversal(root.left));
24 | result.add(root.val);
25 | result.addAll(inorderTraversal(root.right));
26 | }
27 | return result;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Leetcode Problems and Solutions/976. Largest Perimeter Triangle.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths.
4 |
5 | If it is impossible to form any triangle of non-zero area, return 0.
6 |
7 |
8 |
9 | Example 1:
10 |
11 | Input: [2,1,2]
12 | Output: 5
13 | Example 2:
14 |
15 | Input: [1,2,1]
16 | Output: 0
17 | Example 3:
18 |
19 | Input: [3,2,3,4]
20 | Output: 10
21 | Example 4:
22 |
23 | Input: [3,6,2,3]
24 | Output: 8
25 |
26 |
27 | Note:
28 |
29 | 3 <= A.length <= 10000
30 | 1 <= A[i] <= 10^6
31 |
32 | */
33 |
34 | class Solution {
35 | public int largestPerimeter(int[] A) {
36 | //For a >= b >= c, a,b,c can form a triangle if a < b + c
37 |
38 | Arrays.sort(A);
39 | for (int i = A.length - 1; i > 1; --i)
40 | if (A[i] < A[i - 1] + A[i - 2])
41 | return A[i] + A[i - 1] + A[i - 2];
42 | return 0;
43 | }
44 | }
--------------------------------------------------------------------------------
/Misc Notes/Cracking the Coding Interview 4th Edition.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Misc Notes/Cracking the Coding Interview 4th Edition.pdf
--------------------------------------------------------------------------------
/Misc Notes/Cracking the coding Interview 6th Edition.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Misc Notes/Cracking the coding Interview 6th Edition.pdf
--------------------------------------------------------------------------------
/Misc Notes/Java Questions.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Misc Notes/Java Questions.docx
--------------------------------------------------------------------------------
/Misc Notes/Leetcode Solutions Version 1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Misc Notes/Leetcode Solutions Version 1.pdf
--------------------------------------------------------------------------------
/Misc Notes/Leetcode Solutions Version 2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Misc Notes/Leetcode Solutions Version 2.pdf
--------------------------------------------------------------------------------
/Misc Notes/Leetcode Solutions Version 3.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Misc Notes/Leetcode Solutions Version 3.pdf
--------------------------------------------------------------------------------
/Misc Notes/OO File System.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Misc Notes/OO File System.doc
--------------------------------------------------------------------------------
/Misc Notes/OOP Design Ques of the Battleship Game.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Misc Notes/OOP Design Ques of the Battleship Game.pdf
--------------------------------------------------------------------------------
/Misc Notes/Operating Systems quesitons.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/Misc Notes/Operating Systems quesitons.docx
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Leetcode
2 |
3 | Leetcode Questions and my solutions
4 |
5 | It also consists of Full Time Software Engineer-I Assessment Questions with solutions. And also a few useful notes and material needed for interview preparation
6 |
--------------------------------------------------------------------------------
/The Algorithm Design Manual by Steven S. Skiena.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/The Algorithm Design Manual by Steven S. Skiena.pdf
--------------------------------------------------------------------------------
/competitive programming by steven & felix halim.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/competitive programming by steven & felix halim.pdf
--------------------------------------------------------------------------------
/the-design-and-implementation-marshall-kirk-mckusick-george-v-neville-neil(www.ebook-dl.com).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaytorasakar8/Leetcode/a37504749e063e2f511d6ac72d8240b743cfd98f/the-design-and-implementation-marshall-kirk-mckusick-george-v-neville-neil(www.ebook-dl.com).pdf
--------------------------------------------------------------------------------