Full Code of careercup/CtCI-6th-Edition for AI

master 59018cfcb902 cached
592 files
76.0 MB
251.8k tokens
2741 symbols
1 requests
Download .txt
Showing preview only (901K chars total). Download the full file or copy to clipboard to get everything.
Repository: careercup/CtCI-6th-Edition
Branch: master
Commit: 59018cfcb902
Files: 592
Total size: 76.0 MB

Directory structure:
gitextract_k4kr__1r/

├── .classpath
├── .gitignore
├── .gitmodules
├── .project
├── Java/
│   ├── Big O/
│   │   ├── Example_16/
│   │   │   └── Example.java
│   │   └── QVI_11_Print_Sorted_Strings/
│   │       └── Question.java
│   ├── Ch 01. Arrays and Strings/
│   │   ├── Q1_01_Is_Unique/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q1_02_Check_Permutation/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q1_03_URLify/
│   │   │   └── Question.java
│   │   ├── Q1_04_Palindrome_Permutation/
│   │   │   ├── Common.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q1_05_One_Away/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q1_06_String_Compression/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q1_07_Rotate_Matrix/
│   │   │   └── Question.java
│   │   ├── Q1_08_Zero_Matrix/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   └── Q1_09_String_Rotation/
│   │       └── Question.java
│   ├── Ch 02. Linked Lists/
│   │   ├── Q2_01_Remove_Dups/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q2_02_Return_Kth_To_Last/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.cpp
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q2_03_Delete_Middle_Node/
│   │   │   └── Question.java
│   │   ├── Q2_04_Partition/
│   │   │   ├── Question.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q2_05_Sum_Lists/
│   │   │   ├── PartialSum.java
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q2_06_Palindrome/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q2_07_Intersection/
│   │   │   └── Question.java
│   │   └── Q2_08_Loop_Detection/
│   │       └── Question.java
│   ├── Ch 03. Stacks and Queues/
│   │   ├── Introduction/
│   │   │   ├── MyQueue.java
│   │   │   ├── MyStack.java
│   │   │   ├── QueueTester.java
│   │   │   └── StackTester.java
│   │   ├── Q3_01_Three_in_One/
│   │   │   ├── FixedMultiStack.java
│   │   │   ├── FullStackException.java
│   │   │   ├── MultiStack.java
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q3_02_Stack_Min/
│   │   │   ├── NodeWithMin.java
│   │   │   ├── Question.java
│   │   │   ├── StackWithMin.java
│   │   │   └── StackWithMin2.java
│   │   ├── Q3_03_Stack_of_Plates/
│   │   │   ├── Node.java
│   │   │   ├── Question.java
│   │   │   ├── SetOfStacks.java
│   │   │   └── Stack.java
│   │   ├── Q3_04_Queue_via_Stacks/
│   │   │   ├── MyQueue.java
│   │   │   └── Question.java
│   │   ├── Q3_05_Sort_Stack/
│   │   │   └── Question.java
│   │   └── Q3_06_Animal_Shelter/
│   │       ├── Animal.java
│   │       ├── AnimalQueue.java
│   │       ├── Cat.java
│   │       ├── Dog.java
│   │       └── Question.java
│   ├── Ch 04. Trees and Graphs/
│   │   ├── Introduction/
│   │   │   └── Traversals.java
│   │   ├── Q4_01_Route_Between_Nodes/
│   │   │   ├── Graph.java
│   │   │   ├── Node.java
│   │   │   └── Question.java
│   │   ├── Q4_02_Minimal_Tree/
│   │   │   └── Question.java
│   │   ├── Q4_03_List_of_Depths/
│   │   │   ├── QuestionBFS.java
│   │   │   └── QuestionDFS.java
│   │   ├── Q4_04_Check_Balanced/
│   │   │   ├── QuestionBrute.java
│   │   │   └── QuestionImproved.java
│   │   ├── Q4_05_Validate_BST/
│   │   │   ├── IntWrapper.java
│   │   │   ├── Question.java
│   │   │   └── QuestionB.java
│   │   ├── Q4_06_Successor/
│   │   │   └── Question.java
│   │   ├── Q4_07_Build_Order/
│   │   │   ├── DFS/
│   │   │   │   ├── Graph.java
│   │   │   │   ├── Project.java
│   │   │   │   └── Question.java
│   │   │   └── EdgeRemoval/
│   │   │       ├── Graph.java
│   │   │       ├── Project.java
│   │   │       └── Question.java
│   │   ├── Q4_08_First_Common_Ancestor/
│   │   │   ├── Question.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   ├── QuestionE.java
│   │   │   ├── QuestionEBad.java
│   │   │   ├── QuestionF.java
│   │   │   └── Tester.java
│   │   ├── Q4_09_BST_Sequences/
│   │   │   └── Question.java
│   │   ├── Q4_10_Check_Subtree/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q4_11_Random_Node/
│   │   │   ├── Question.java
│   │   │   ├── Tree.java
│   │   │   └── TreeNode.java
│   │   └── Q4_12_Paths_with_Sum/
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       └── Tester.java
│   ├── Ch 05. Bit Manipulation/
│   │   ├── Q5_01_Insertion/
│   │   │   └── Question.java
│   │   ├── Q5_02_Binary_to_String/
│   │   │   └── Question.java
│   │   ├── Q5_03_Flip_Bit_to_Win/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q5_04_Next_Number/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q5_06_Conversion/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q5_07_Pairwise_Swap/
│   │   │   └── Question.java
│   │   ├── Q5_08_Draw_Line/
│   │   │   └── Question.java
│   │   └── Sample_Code/
│   │       ├── RightShifts.java
│   │       └── Sample_Code.java
│   ├── Ch 06. Math and Logic Puzzles/
│   │   ├── Introduction/
│   │   │   ├── PrimeNumbers.java
│   │   │   └── SieveOfEratosthenes.java
│   │   ├── Q6_05_Egg_Drop/
│   │   │   └── Question.java
│   │   ├── Q6_07_The_Apocalypse/
│   │   │   └── Question.java
│   │   └── Q6_10_Test_Strips/
│   │       ├── Bottle.java
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       ├── QuestionC.java
│   │       └── TestStrip.java
│   ├── Ch 07. Object-Oriented Design/
│   │   ├── Q7_01_Deck_of_Cards/
│   │   │   ├── BlackJackCard.java
│   │   │   ├── BlackJackGameAutomator.java
│   │   │   ├── BlackJackHand.java
│   │   │   ├── Card.java
│   │   │   ├── Deck.java
│   │   │   ├── Hand.java
│   │   │   ├── Question.java
│   │   │   └── Suit.java
│   │   ├── Q7_02_Call_Center/
│   │   │   ├── Call.java
│   │   │   ├── CallHandler.java
│   │   │   ├── Caller.java
│   │   │   ├── Director.java
│   │   │   ├── Employee.java
│   │   │   ├── Manager.java
│   │   │   ├── Rank.java
│   │   │   ├── Respondent.java
│   │   │   └── Test.java
│   │   ├── Q7_03_Jukebox/
│   │   │   ├── CD.java
│   │   │   ├── CDPlayer.java
│   │   │   ├── JukeBox.java
│   │   │   ├── Playlist.java
│   │   │   ├── Song.java
│   │   │   ├── SongSelector.java
│   │   │   └── User.java
│   │   ├── Q7_04_Parking_Lot/
│   │   │   ├── Bus.java
│   │   │   ├── Car.java
│   │   │   ├── Level.java
│   │   │   ├── Motorcycle.java
│   │   │   ├── ParkingLot.java
│   │   │   ├── ParkingSpot.java
│   │   │   ├── Question.java
│   │   │   ├── Vehicle.java
│   │   │   └── VehicleSize.java
│   │   ├── Q7_05_Online_Book_Reader/
│   │   │   ├── Book.java
│   │   │   ├── Display.java
│   │   │   ├── Library.java
│   │   │   ├── OnlineReaderSystem.java
│   │   │   ├── User.java
│   │   │   └── UserManager.java
│   │   ├── Q7_06_Jigsaw/
│   │   │   ├── Edge.java
│   │   │   ├── Orientation.java
│   │   │   ├── Piece.java
│   │   │   ├── Puzzle.java
│   │   │   ├── Question.java
│   │   │   └── Shape.java
│   │   ├── Q7_07_Chat_Server/
│   │   │   ├── AddRequest.java
│   │   │   ├── Conversation.java
│   │   │   ├── GroupChat.java
│   │   │   ├── Message.java
│   │   │   ├── PrivateChat.java
│   │   │   ├── RequestStatus.java
│   │   │   ├── System.java
│   │   │   ├── User.java
│   │   │   ├── UserManager.java
│   │   │   ├── UserStatus.java
│   │   │   └── UserStatusType.java
│   │   ├── Q7_08_Othello/
│   │   │   ├── Automator.java
│   │   │   ├── Board.java
│   │   │   ├── Color.java
│   │   │   ├── Direction.java
│   │   │   ├── Game.java
│   │   │   ├── Location.java
│   │   │   ├── Piece.java
│   │   │   ├── Player.java
│   │   │   └── Question.java
│   │   ├── Q7_09_Circular_Array/
│   │   │   ├── CircularArray.java
│   │   │   └── Question.java
│   │   ├── Q7_10_Minesweeper/
│   │   │   ├── Board.java
│   │   │   ├── Cell.java
│   │   │   ├── Game.java
│   │   │   ├── Question.java
│   │   │   ├── UserPlay.java
│   │   │   └── UserPlayResult.java
│   │   ├── Q7_11_File_System/
│   │   │   ├── Directory.java
│   │   │   ├── Entry.java
│   │   │   ├── File.java
│   │   │   └── Question.java
│   │   └── Q7_12_Hash_Table/
│   │       ├── Dummy.java
│   │       ├── Hasher.java
│   │       └── Question.java
│   ├── Ch 08. Recursion and Dynamic Programming/
│   │   ├── Introduction/
│   │   │   ├── FibonacciA.java
│   │   │   ├── FibonacciB.java
│   │   │   ├── FibonacciC.java
│   │   │   └── FibonacciD.java
│   │   ├── Q8_01_Triple_Step/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q8_02_Robot_in_a_Grid/
│   │   │   ├── Point.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q8_03_Magic_Index/
│   │   │   ├── Question.java
│   │   │   └── QuestionB.java
│   │   ├── Q8_04_Power_Set/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q8_05_Recursive_Multiply/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q8_06_Towers_of_Hanoi/
│   │   │   ├── Question.java
│   │   │   └── Tower.java
│   │   ├── Q8_07_Permutations_Without_Dups/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── QuestionC.java
│   │   ├── Q8_08_Permutations_With_Dups/
│   │   │   └── Question.java
│   │   ├── Q8_09_Parens/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q8_10_Paint_Fill/
│   │   │   └── Question.java
│   │   ├── Q8_11_Coins/
│   │   │   ├── Question.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q8_12_Eight_Queens/
│   │   │   └── Question.java
│   │   ├── Q8_13_Stack_of_Boxes/
│   │   │   ├── Box.java
│   │   │   ├── BoxComparator.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   └── Q8_14_Boolean_Evaluation/
│   │       ├── Others.java
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       ├── QuestionC.java
│   │       └── Tester.java
│   ├── Ch 09. Scalability and Memory Limits/
│   │   ├── Q9_02_Social_Network/
│   │   │   ├── BFSData.java
│   │   │   ├── Machine.java
│   │   │   ├── PathNode.java
│   │   │   ├── Person.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── Server.java
│   │   │   └── Tester.java
│   │   └── Q9_05_Cache/
│   │       ├── Cache.java
│   │       ├── Node.java
│   │       └── Question.java
│   ├── Ch 10. Sorting and Searching/
│   │   ├── Introduction/
│   │   │   ├── BinarySearch.java
│   │   │   ├── MergeSort.java
│   │   │   └── Quicksort.java
│   │   ├── Q10_01_Sorted_Merge/
│   │   │   └── Question.java
│   │   ├── Q10_02_Group_Anagrams/
│   │   │   ├── AnagramComparator.java
│   │   │   ├── Question.java
│   │   │   └── QuestionB.java
│   │   ├── Q10_03_Search_in_Rotated_Array/
│   │   │   └── Question.java
│   │   ├── Q10_04_Sorted_Search_No_Size/
│   │   │   └── Arrayish/
│   │   │       ├── Listy.java
│   │   │       └── Question.java
│   │   ├── Q10_05_Sparse_Search/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q10_07_Missing_Int/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── input.txt
│   │   ├── Q10_08_Find_Duplicates/
│   │   │   ├── BitSet.java
│   │   │   └── Question.java
│   │   ├── Q10_09_Sorted_Matrix_Search/
│   │   │   ├── Coordinate.java
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q10_10_Rank_from_Stream/
│   │   │   ├── IntComparable.java
│   │   │   ├── Question.java
│   │   │   └── RankNode.java
│   │   └── Q10_11_Peaks_and_Valleys/
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       ├── QuestionC.java
│   │       └── Tester.java
│   ├── Ch 13. Java/
│   │   ├── Introduction/
│   │   │   ├── Ambiguous.java
│   │   │   ├── Circle.java
│   │   │   ├── Introduction.java
│   │   │   ├── IntroductionCollections.java
│   │   │   ├── IntroductionOverriding.java
│   │   │   ├── Shape.java
│   │   │   └── Square.java
│   │   ├── Q13_01_Private_Constructor/
│   │   │   └── Question.java
│   │   ├── Q13_05_TreeMap_HashMap_LinkedHashMap/
│   │   │   └── Question.java
│   │   ├── Q13_06_Object_Reflection/
│   │   │   ├── Question.java
│   │   │   └── Rectangle.java
│   │   ├── Q13_07_Lambda_Expressions/
│   │   │   ├── Country.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   └── Q13_08_Lambda_Random/
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       └── QuestionC.java
│   ├── Ch 15. Threads and Locks/
│   │   ├── IntroductionA/
│   │   │   ├── ExampleA.java
│   │   │   └── RunnableThreadExample.java
│   │   ├── IntroductionB/
│   │   │   ├── ExampleB.java
│   │   │   └── ThreadExample.java
│   │   ├── IntroductionLocks/
│   │   │   ├── Intro.java
│   │   │   ├── LockedATM.java
│   │   │   ├── MyClass.java
│   │   │   └── NoLockATM.java
│   │   ├── IntroductionSynchronization/
│   │   │   ├── Intro.java
│   │   │   ├── MyClass.java
│   │   │   └── MyObject.java
│   │   ├── IntroductionSynchronizedBlocks/
│   │   │   ├── Intro.java
│   │   │   ├── MyClass.java
│   │   │   └── MyObject.java
│   │   ├── IntroductionWaitNotify/
│   │   │   ├── Intro.java
│   │   │   ├── MyClass.java
│   │   │   └── MyObject.java
│   │   ├── Q15_03_Dining_Philosophers/
│   │   │   ├── QuestionA/
│   │   │   │   ├── Chopstick.java
│   │   │   │   ├── Philosopher.java
│   │   │   │   └── Question.java
│   │   │   └── QuestionB/
│   │   │       ├── Chopstick.java
│   │   │       ├── Philosopher.java
│   │   │       └── Question.java
│   │   ├── Q15_04_Deadlock_Free_Class/
│   │   │   ├── LockFactory.java
│   │   │   ├── LockNode.java
│   │   │   └── Question.java
│   │   ├── Q15_05_Call_In_Order/
│   │   │   ├── Foo.java
│   │   │   ├── FooBad.java
│   │   │   ├── MyThread.java
│   │   │   └── Question.java
│   │   ├── Q15_06_Synchronized_Methods/
│   │   │   ├── Foo.java
│   │   │   ├── MyThread.java
│   │   │   └── Question.java
│   │   └── Q15_07_FizzBuzz/
│   │       ├── FBThread.java
│   │       ├── FizzBuzzThread.java
│   │       ├── NumberThread.java
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       └── QuestionC.java
│   ├── Ch 16. Moderate/
│   │   ├── Q16_01_Number_Swapper/
│   │   │   └── Question.java
│   │   ├── Q16_02_Word_Frequencies/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q16_03_Intersection/
│   │   │   ├── Line.java
│   │   │   ├── Point.java
│   │   │   ├── Question.java
│   │   │   └── Tester.java
│   │   ├── Q16_04_Tic_Tac_Win/
│   │   │   ├── Piece.java
│   │   │   ├── Position.java
│   │   │   ├── PositionIterator.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   ├── QuestionE.java
│   │   │   ├── QuestionF.java
│   │   │   ├── QuestionG.java
│   │   │   ├── QuestionH.java
│   │   │   └── Tester.java
│   │   ├── Q16_05_Factorial_Zeros/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q16_06_Smallest_Difference/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q16_07_Number_Max/
│   │   │   └── Question.java
│   │   ├── Q16_08_English_Int/
│   │   │   └── Question.java
│   │   ├── Q16_09_Operations/
│   │   │   └── Question.java
│   │   ├── Q16_10_Living_People/
│   │   │   ├── Person.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q16_11_Diving_Board/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q16_12_XML_Encoding/
│   │   │   ├── Attribute.java
│   │   │   ├── Element.java
│   │   │   ├── QuestionOO.java
│   │   │   └── QuestionString.java
│   │   ├── Q16_13_Bisect_Squares/
│   │   │   ├── Line.java
│   │   │   ├── Point.java
│   │   │   ├── Question.java
│   │   │   ├── Square Cut Tester - Q16_13.xlsx
│   │   │   └── Square.java
│   │   ├── Q16_14_Best_Line/
│   │   │   ├── GraphPoint.java
│   │   │   ├── Line.java
│   │   │   └── Question.java
│   │   ├── Q16_15_Master_Mind/
│   │   │   ├── Question.java
│   │   │   ├── Result.java
│   │   │   └── Tester.java
│   │   ├── Q16_16_Sub_Sort/
│   │   │   ├── Question.java
│   │   │   ├── QuestionB.java
│   │   │   ├── Range.java
│   │   │   └── Tester.java
│   │   ├── Q16_17_Contiguous_Sequence/
│   │   │   └── Question.java
│   │   ├── Q16_18_Pattern_Matcher/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q16_19_Pond_Sizes/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q16_20_T9/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── QuestionC.java
│   │   ├── Q16_21_Sum_Swap/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q16_22_Langtons_Ant/
│   │   │   ├── Ant.java
│   │   │   ├── Board.java
│   │   │   ├── Grid.java
│   │   │   ├── Orientation.java
│   │   │   ├── Position.java
│   │   │   └── Question.java
│   │   ├── Q16_23_Rand7_From_Rand5/
│   │   │   ├── Question.java
│   │   │   └── QuestionB.java
│   │   ├── Q16_24_Pairs_With_Sum/
│   │   │   ├── Pair.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q16_25_LRU_Cache/
│   │   │   ├── Cache.java
│   │   │   └── Question.java
│   │   └── Q16_26_Calculator/
│   │       ├── Operator.java
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       └── Term.java
│   ├── Ch 17. Hard/
│   │   ├── Q17_01_Add_Without_Plus/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q17_02_Shuffle/
│   │   │   └── Question.java
│   │   ├── Q17_03_Random_Set/
│   │   │   ├── Question.java
│   │   │   └── QuestionAlternate.java
│   │   ├── Q17_04_Missing_Number/
│   │   │   ├── BitInteger.java
│   │   │   └── Question.java
│   │   ├── Q17_05_Letters_and_Numbers/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q17_06_Count_of_2s/
│   │   │   ├── Question.java
│   │   │   └── QuestionBrute.java
│   │   ├── Q17_07_Baby_Names/
│   │   │   ├── Graph.java
│   │   │   ├── GraphNode.java
│   │   │   ├── NameSet.java
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q17_08_Circus_Tower/
│   │   │   ├── HtWt.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionOld.java
│   │   │   └── Tester.java
│   │   ├── Q17_09_Kth_Multiple/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── QuestionC.java
│   │   ├── Q17_10_Majority_Element/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q17_11_Word_Distance/
│   │   │   ├── LocationPair.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q17_12_BiNode/
│   │   │   ├── BiNode.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── QuestionC.java
│   │   ├── Q17_13_ReSpace/
│   │   │   ├── ParseResult.java
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q17_14_Smallest_K/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q17_15_Longest_Word/
│   │   │   ├── LengthComparator.java
│   │   │   └── Question.java
│   │   ├── Q17_16_The_Masseuse/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q17_17_Multi_Search/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── Trie.java
│   │   │   └── TrieNode.java
│   │   ├── Q17_18_Shortest_Supersequence/
│   │   │   ├── HeapNode.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   ├── QuestionE.java
│   │   │   ├── Range.java
│   │   │   └── Tester.java
│   │   ├── Q17_19_Missing_Two/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── QuestionC.java
│   │   ├── Q17_20_Continuous_Median/
│   │   │   ├── MaxHeapComparator.java
│   │   │   ├── MinHeapComparator.java
│   │   │   └── Question.java
│   │   ├── Q17_21_Volume_of_Histogram/
│   │   │   ├── HistogramData.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q17_22_Word_Transformer/
│   │   │   ├── BFSData.java
│   │   │   ├── PathNode.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q17_23_Max_Black_Square/
│   │   │   ├── Question.java
│   │   │   ├── QuestionEff.java
│   │   │   ├── SquareCell.java
│   │   │   └── Subsquare.java
│   │   ├── Q17_24_Max_Submatrix/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── Range.java
│   │   │   ├── SubMatrix.java
│   │   │   └── Tester.java
│   │   ├── Q17_25_Word_Rectangle/
│   │   │   ├── Question.java
│   │   │   ├── Rectangle.java
│   │   │   └── WordGroup.java
│   │   └── Q17_26_Sparse_Similarity/
│   │       ├── DocPair.java
│   │       ├── Document.java
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       ├── QuestionC.java
│   │       └── Tester.java
│   ├── CtCILibrary/
│   │   └── CtCILibrary/
│   │       ├── AssortedMethods.java
│   │       ├── BTreePrinter.java
│   │       ├── BitVector.java
│   │       ├── HashMapList.java
│   │       ├── LinkedListNode.java
│   │       ├── TreeNode.java
│   │       ├── Trie.java
│   │       └── TrieNode.java
│   └── Introduction/
│       ├── Big_O/
│       │   ├── Ex_01.java
│       │   ├── Ex_02.java
│       │   ├── Ex_03.java
│       │   ├── Ex_04.java
│       │   ├── Ex_05.java
│       │   ├── Ex_06.java
│       │   ├── Ex_07.java
│       │   ├── Ex_08.java
│       │   ├── Ex_09.java
│       │   ├── Ex_10.java
│       │   ├── Ex_11.java
│       │   ├── Ex_14.java
│       │   ├── Ex_15.java
│       │   ├── Ex_16.java
│       │   ├── Ex_17.java
│       │   ├── Ex_18.java
│       │   ├── Ex_19.java
│       │   ├── Ex_20.java
│       │   ├── Q_01.java
│       │   ├── Q_02.java
│       │   ├── Q_03.java
│       │   ├── Q_04.java
│       │   ├── Q_05.java
│       │   ├── Q_06.java
│       │   ├── Q_09.java
│       │   ├── Q_10.java
│       │   ├── Q_11.java
│       │   └── Q_12.java
│       ├── CompareBinaryToHex/
│       │   └── CompareBinaryToHex.java
│       └── SwapMinMax/
│           └── SwapMinMax.java
└── README.md

================================================
FILE CONTENTS
================================================

================================================
FILE: .classpath
================================================
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path="Java/Introduction"/>
	<classpathentry kind="src" path="Java/Big O"/>
	<classpathentry kind="src" path="Java/Ch 01. Arrays and Strings"/>
	<classpathentry kind="src" path="Java/Ch 02. Linked Lists"/>
	<classpathentry kind="src" path="Java/Ch 03. Stacks and Queues"/>
	<classpathentry kind="src" path="Java/Ch 04. Trees and Graphs"/>
	<classpathentry kind="src" path="Java/Ch 05. Bit Manipulation"/>
	<classpathentry kind="src" path="Java/Ch 06. Math and Logic Puzzles"/>
	<classpathentry kind="src" path="Java/Ch 07. Object-Oriented Design"/>
	<classpathentry kind="src" path="Java/Ch 08. Recursion and Dynamic Programming"/>
	<classpathentry kind="src" path="Java/Ch 09. Scalability and Memory Limits"/>
	<classpathentry kind="src" path="Java/Ch 10. Sorting and Searching"/>
	<classpathentry kind="src" path="Java/Ch 13. Java"/>
	<classpathentry kind="src" path="Java/Ch 16. Moderate"/>
	<classpathentry kind="src" path="Java/Ch 15. Threads and Locks"/>
	<classpathentry kind="src" path="Java/Ch 17. Hard"/>
	<classpathentry kind="src" path="Java/CtCILibrary"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
	<classpathentry kind="output" path="bin"/>
</classpath>


================================================
FILE: .gitignore
================================================
bin/


================================================
FILE: .gitmodules
================================================
[submodule "php"]
	path = php
	url = https://github.com/careercup/CtCI-6th-Edition-php.git
[submodule "cpp"]
	path = cpp
	url = https://github.com/careercup/CtCI-6th-Edition-cpp.git
[submodule "Clojure"]
	path = Clojure
	url = https://github.com/careercup/CtCI-6th-Edition-Clojure.git
[submodule "Groovy"]
	path = Groovy
	url = https://github.com/careercup/CtCI-6th-Edition-Groovy.git
[submodule "Python"]
	path = Python
	url = https://github.com/careercup/CtCI-6th-Edition-Python.git
[submodule "Swift"]
	path = Swift
	url = https://github.com/careercup/CtCI-6th-Edition-Swift.git
[submodule "Haskell"]
	path = Haskell
	url = https://github.com/careercup/CtCI-6th-Edition-Haskell.git
[submodule "JavaScript"]
	path = JavaScript
	url = https://github.com/careercup/CtCI-6th-Edition-JavaScript.git
[submodule "JavaScript-ES2015"]
	path = JavaScript-ES2015
	url = https://github.com/careercup/CtCI-6th-Edition-JavaScript-ES2015.git
[submodule "Go"]
	path = Go
	url = https://github.com/careercup/CtCI-6th-Edition-Go.git
[submodule "CtCI-6th-Edition-CSharp"]
	path = CSharp
	url = https://github.com/careercup/CtCI-6th-Edition-CSharp.git
[submodule "c"]
	path = c
	url = https://github.com/careercup/CtCI-6th-Edition-C.git
[submodule "Objective-C"]
	path = Objective-C
	url = https://github.com/careercup/CtCI-6th-Edition-Objective-C.git
[submodule "Julia"]
	path = Julia
	url = https://github.com/careercup/CtCI-6th-Edition-Julia.git
[submodule "Ruby"]
	path = Ruby
	url = https://github.com/careercup/CtCI-6th-Edition-Ruby.git
[submodule "Kotlin"]
	path = Kotlin
	url = https://github.com/careercup/CtCI-6th-Edition-Kotlin.git


================================================
FILE: .project
================================================
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>CtCIv6</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.jdt.core.javanature</nature>
	</natures>
</projectDescription>


================================================
FILE: Java/Big O/Example_16/Example.java
================================================
package Example_16;

public class Example {

	public static int powersOf2(int n) {
		if (n < 1) {
			return 0;
		} else if (n == 1) {
			System.out.println(1);
			return 1;
		} else {
			int prev = powersOf2(n / 2);
			int curr = prev * 2;
			System.out.println(curr);
			return curr;
		}
	}
	
	public static void main(String[] args) {
		powersOf2(4);
	}

}


================================================
FILE: Java/Big O/QVI_11_Print_Sorted_Strings/Question.java
================================================
package QVI_11_Print_Sorted_Strings;


public class Question {

	public static int numChars = 26;
	
	public static void printSortedStrings(int remaining) {
		printSortedStrings(remaining, "");
	}
	
	public static void printSortedStrings(int remaining, String prefix) {
		if (remaining == 0) {
			if (isInOrder(prefix)) {
				System.out.println(prefix);
			}
		} else {
			for (int i = 0; i < numChars; i++) {
				char c = ithLetter(i);
				printSortedStrings(remaining - 1, prefix + c);
			}
		}
	}
	
	public static boolean isInOrder(String s) {
		boolean isInOrder = true;
		for (int i = 1; i < s.length(); i++) {
			int prev = ithLetter(s.charAt(i - 1));
			int curr = ithLetter(s.charAt(i));
			if (prev > curr) {
				isInOrder = false;
			}
		}
		return isInOrder;
	}
	
	public static char ithLetter(int i) {
		return (char) (((int) 'a') + i);
	}
	
	public static void main(String[] args) {
		printSortedStrings(5);
	}

}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_01_Is_Unique/QuestionA.java
================================================
package Q1_01_Is_Unique;

public class QuestionA {
	public static boolean isUniqueChars(String str) {
		if (str.length() > 128) {
			return false;
		}
		boolean[] char_set = new boolean[128];
		for (int i = 0; i < str.length(); i++) {
			int val = str.charAt(i);
			if (char_set[val]) return false;
			char_set[val] = true;
		}
		return true;
	}
	
	public static void main(String[] args) {
		String[] words = {"abcde", "hello", "apple", "kite", "padle"};
		for (String word : words) {
			System.out.println(word + ": " + isUniqueChars(word));
		}
	}

}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_01_Is_Unique/QuestionB.java
================================================
package Q1_01_Is_Unique;

public class QuestionB {

	/* Assumes only letters a through z. */
	public static boolean isUniqueChars(String str) {
		if (str.length() > 26) { // Only 26 characters
			return false;
		}
		int checker = 0;
		for (int i = 0; i < str.length(); i++) {
			int val = str.charAt(i) - 'a';
			if ((checker & (1 << val)) > 0) return false;
			checker |= (1 << val);
		}
		return true;
	}
	
	public static void main(String[] args) {
		String[] words = {"abcde", "hello", "apple", "kite", "padle"};
		for (String word : words) {
			System.out.println(word + ": " + isUniqueChars(word));
		}
	}

}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_01_Is_Unique/Tester.java
================================================
package Q1_01_Is_Unique;

public class Tester {
	
	public static void main(String[] args) {
		String[] words = {"abcde", "hello", "apple", "kite", "padle"};
		for (String word : words) {
			boolean wordA =  QuestionA.isUniqueChars(word);
			boolean wordB =  QuestionB.isUniqueChars(word);
			if (wordA == wordB) {
				System.out.println(word + ": " + wordA);
			} else {
				System.out.println(word + ": " + wordA + " vs " + wordB);
			}
		}
	}
}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_02_Check_Permutation/QuestionA.java
================================================
package Q1_02_Check_Permutation;

public class QuestionA {	
	public static String sort(String s) {
		char[] content = s.toCharArray();
		java.util.Arrays.sort(content);
		return new String(content);
	}
	
	public static boolean permutation(String s, String t) {
		return sort(s).equals(sort(t));
	}	
	
	public static void main(String[] args) {
		String[][] pairs = {{"apple", "papel"}, {"carrot", "tarroc"}, {"hello", "llloh"}};
		for (String[] pair : pairs) {
			String word1 = pair[0];
			String word2 = pair[1];
			boolean anagram = permutation(word1, word2);
			System.out.println(word1 + ", " + word2 + ": " + anagram);
		}
	}
}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_02_Check_Permutation/QuestionB.java
================================================
package Q1_02_Check_Permutation;

public class QuestionB {	
	public static boolean permutation(String s, String t) {
		if (s.length() != t.length()) return false; // Permutations must be same length
		
		int[] letters = new int[128]; // Assumption: ASCII
		for (int i = 0; i < s.length(); i++) {
			letters[s.charAt(i)]++;
		}
		  
		for (int i = 0; i < t.length(); i++) {
			letters[t.charAt(i)]--;
		    if (letters[t.charAt(i)] < 0) {
		    	return false;
		    }
		}
		  
		return true; // letters array has no negative values, and therefore no positive values either
	}
	
	public static void main(String[] args) {
		String[][] pairs = {{"apple", "papel"}, {"carrot", "tarroc"}, {"hello", "llloh"}};
		for (String[] pair : pairs) {
			String word1 = pair[0];
			String word2 = pair[1];
			boolean anagram = permutation(word1, word2);
			System.out.println(word1 + ", " + word2 + ": " + anagram);
		}
	}
}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_03_URLify/Question.java
================================================
package Q1_03_URLify;

import CtCILibrary.AssortedMethods;

public class Question {
	// Assume string has sufficient free space at the end
	public static void replaceSpaces(char[] str, int trueLength) {
		int spaceCount = 0, index, i = 0;
		for (i = 0; i < trueLength; i++) {
			if (str[i] == ' ') {
				spaceCount++;
			}
		}
		index = trueLength + spaceCount * 2;
		if (trueLength < str.length) str[trueLength] = '\0';
		for (i = trueLength - 1; i >= 0; i--) {
			if (str[i] == ' ') {
				str[index - 1] = '0';
				str[index - 2] = '2';
				str[index - 3] = '%';
				index = index - 3;
			} else {
				str[index - 1] = str[i];
				index--;
			}
		}
	}
	
	public static int findLastCharacter(char[] str) {
		for (int i = str.length - 1; i >= 0; i--) {
			if (str[i] != ' ') {
				return i;
			}
		}
		return -1;
	}
	
	public static void main(String[] args) {
		String str = "Mr John Smith    ";
		char[] arr = str.toCharArray();
		int trueLength = findLastCharacter(arr) + 1;
		replaceSpaces(arr, trueLength);	
		System.out.println("\"" + AssortedMethods.charArrayToString(arr) + "\"");
	}
}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/Common.java
================================================
package Q1_04_Palindrome_Permutation;

public class Common {

	public static int getCharNumber(Character c) {
		int a = Character.getNumericValue('a');
		int z = Character.getNumericValue('z');
		
		int val = Character.getNumericValue(c);
		if (a <= val && val <= z) {
			return val - a;
		}
		return -1;
	}
	
	public static int[] buildCharFrequencyTable(String phrase) {
		int[] table = new int[Character.getNumericValue('z') - Character.getNumericValue('a') + 1];
		for (char c : phrase.toCharArray()) {
			int x = getCharNumber(c);
			if (x != -1) {
				table[x]++;
			}
		}
		return table;
	}

}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/QuestionA.java
================================================
package Q1_04_Palindrome_Permutation;

public class QuestionA {	
	public static boolean checkMaxOneOdd(int[] table) {
		boolean foundOdd = false;
		for (int count : table) {
			if (count % 2 == 1) {
				if (foundOdd) {
					return false;
				}
				foundOdd = true;
			}
		}
		return true;
	}
	
	public static boolean isPermutationOfPalindrome(String phrase) {
		int[] table = Common.buildCharFrequencyTable(phrase);
		return checkMaxOneOdd(table);
	}
	
	public static void main(String[] args) {
		String pali = "Rats live on no evil star";
		System.out.println(isPermutationOfPalindrome(pali));
	}


}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/QuestionB.java
================================================
package Q1_04_Palindrome_Permutation;

public class QuestionB {	

	public static boolean isPermutationOfPalindrome(String phrase) {
		int countOdd = 0;
		int[] table = new int[Character.getNumericValue('z') - Character.getNumericValue('a') + 1];
		for (char c : phrase.toCharArray()) {
			int x = Common.getCharNumber(c);
			if (x != -1) {
				table[x]++;

				if (table[x] % 2 == 1) {
					countOdd++;
				} else {
					countOdd--;
				}
			}
		}
		return countOdd <= 1;
	}
	
	public static void main(String[] args) {
		String pali = "Ratzs live on no evil starz";
		System.out.println(isPermutationOfPalindrome(pali));
		String pali2 = "Zeus was deified, saw Suez";
		System.out.println(isPermutationOfPalindrome(pali2));
	}


}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/QuestionC.java
================================================
package Q1_04_Palindrome_Permutation;

public class QuestionC {
	/* Toggle the ith bit in the integer. */
	public static int toggle(int bitVector, int index) {
		if (index < 0) return bitVector;
		
		int mask = 1 << index;
		if ((bitVector & mask) == 0) {
			bitVector |= mask;
		} else {
			bitVector &= ~mask;
		}
		return bitVector;
	}
	
	/* Create bit vector for string. For each letter with value i,
	 * toggle the ith bit. */
	public static int createBitVector(String phrase) {
		int bitVector = 0;
		for (char c : phrase.toCharArray()) {
			int x = Common.getCharNumber(c);
			bitVector = toggle(bitVector, x);
		}
		return bitVector;
	}
	
	/* Check that at most one bit is set by subtracting one from the 
	 * integer and ANDing it with the original integer. */
	public static boolean checkAtMostOneBitSet(int bitVector) {
		return (bitVector & (bitVector - 1)) == 0;
	}
	
	public static boolean isPermutationOfPalindrome(String phrase) {
		int bitVector = createBitVector(phrase);
		return checkAtMostOneBitSet(bitVector);
	}
	
	public static void main(String[] args) {
		String pali = "Rats live on no evil star";
		System.out.println(isPermutationOfPalindrome(pali));
	}
}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/Tester.java
================================================
package Q1_04_Palindrome_Permutation;

public class Tester {

	
	public static void main(String[] args) {
		String[] strings = {"Rats live on no evil star",
							"A man, a plan, a canal, panama",
							"Lleve",
							"Tacotac",
							"asda"};
		for (String s : strings) {
			boolean a = QuestionA.isPermutationOfPalindrome(s);
			boolean b = QuestionB.isPermutationOfPalindrome(s);
			boolean c = QuestionC.isPermutationOfPalindrome(s);
			System.out.println(s);
			if (a == b && b == c) {
				System.out.println("Agree: " + a);
			} else {
				System.out.println("Disagree: " + a + ", " + b + ", " + c);
			}
			System.out.println();
		}

	}

}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionA.java
================================================
package Q1_05_One_Away;

public class QuestionA {

	public static boolean oneEditReplace(String s1, String s2) {
		boolean foundDifference = false;
		for (int i = 0; i < s1.length(); i++) {
			if (s1.charAt(i) != s2.charAt(i)) {
				if (foundDifference) {
					return false;
				}
				
				foundDifference = true;
			}
		}
		return true;
	}
	
	/* Check if you can insert a character into s1 to make s2. */
	public static boolean oneEditInsert(String s1, String s2) {
		int index1 = 0;
		int index2 = 0;
		while (index2 < s2.length() && index1 < s1.length()) {
			if (s1.charAt(index1) != s2.charAt(index2)) {
				if (index1 != index2) {
					return false;
				}		
				index2++;
			} else {
				index1++;
				index2++;
			}
		}
		return true;
	}	
	
	public static boolean oneEditAway(String first, String second) {
		if (first.length() == second.length()) {
			return oneEditReplace(first, second);
		} else if (first.length() + 1 == second.length()) {
			return oneEditInsert(first, second);
		} else if (first.length() - 1 == second.length()) {
			return oneEditInsert(second, first);
		} 
		return false;
	}
	
	public static void main(String[] args) {
		String a = "pse";
		String b = "pale";
		boolean isOneEdit = oneEditAway(a, b);
		System.out.println(a + ", " + b + ": " + isOneEdit);
	}

}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionB.java
================================================
package Q1_05_One_Away;

public class QuestionB {	
public static boolean oneEditAway(String first, String second) {
		/* Length checks. */
		if (Math.abs(first.length() - second.length()) > 1) {
			return false;
		}
		
		/* Get shorter and longer string.*/
		String s1 = first.length() < second.length() ? first : second;
		String s2 = first.length() < second.length() ? second : first;

		int index1 = 0;
		int index2 = 0;
		boolean foundDifference = false;
		while (index2 < s2.length() && index1 < s1.length()) {
			if (s1.charAt(index1) != s2.charAt(index2)) {
				/* Ensure that this is the first difference found.*/
				if (foundDifference) return false;
				foundDifference = true;
				if (s1.length() == s2.length()) { // On replace, move shorter pointer
					index1++;
				}
			} else {
				index1++; // If matching, move shorter pointer 
			}
			index2++; // Always move pointer for longer string 
		}
		return true;
	}
	
	
	
	public static void main(String[] args) {
		String a = "palee";
		String b = "pale";
		boolean isOneEdit1 = oneEditAway(a, b);
		System.out.println(a + ", " + b + ": " + isOneEdit1);

		String c = "pale";
		String d = "pkle";
		boolean isOneEdit2 = oneEditAway(c, d);
		System.out.println(c + ", " + d + ": " + isOneEdit2);
	}

}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_05_One_Away/Tester.java
================================================
package Q1_05_One_Away;

public class Tester {
	
	public static void test(String a, String b, boolean expected) {
		boolean resultA = QuestionA.oneEditAway(a, b);
		boolean resultB = QuestionB.oneEditAway(a, b);		
		
		if (resultA == expected && resultB == expected) {
			System.out.println(a + ", " + b + ": success");
		} else {
			System.out.println(a + ", " + b + ": error");
		}
	}
	
	public static void main(String[] args) {
		String[][] tests = {{"a", "b", "true"}, 
				{"", "d", "true"},
				{"d", "de", "true"},
				{"pale", "pse", "false"},
				{"acdsfdsfadsf", "acdsgdsfadsf", "true"},
				{"acdsfdsfadsf", "acdsfdfadsf", "true"},
				{"acdsfdsfadsf", "acdsfdsfads", "true"},
				{"acdsfdsfadsf", "cdsfdsfadsf", "true"},
				{"adfdsfadsf", "acdfdsfdsf", "false"},
				{"adfdsfadsf", "bdfdsfadsg", "false"},
				{"adfdsfadsf", "affdsfads", "false"},
				{"pale", "pkle", "true"},
				{"pkle", "pable", "false"}};
		for (int i = 0; i < tests.length; i++) {
			String[] test = tests[i];
			String a = test[0];
			String b = test[1];
			boolean expected = test[2].equals("true");
			
			test(a, b, expected);
			test(b, a, expected);
		}
		
	}

}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_06_String_Compression/QuestionA.java
================================================
package Q1_06_String_Compression;

public class QuestionA {	
	public static String compressBad(String str) {
		String compressedString = "";
		int countConsecutive = 0;
		for (int i = 0; i < str.length(); i++) {
			countConsecutive++;
			
			/* If next character is different than current, append this char to result.*/
			if (i + 1 >= str.length() || str.charAt(i) != str.charAt(i + 1)) {
				compressedString += "" + str.charAt(i) + countConsecutive;
				countConsecutive = 0;
			}
		}
		return compressedString.length() < str.length() ? compressedString : str;
	}
	
	public static void main(String[] args) {
		String str = "aa";
		System.out.println(str);
		System.out.println(compressBad(str));
	}
}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_06_String_Compression/QuestionB.java
================================================
package Q1_06_String_Compression;

public class QuestionB {	
	public static String compress(String str) {
		StringBuilder compressed = new StringBuilder();
		int countConsecutive = 0;
		for (int i = 0; i < str.length(); i++) {
			countConsecutive++;
			
			/* If next character is different than current, append this char to result.*/
			if (i + 1 >= str.length() || str.charAt(i) != str.charAt(i + 1)) {
				compressed.append(str.charAt(i));
				compressed.append(countConsecutive);
				countConsecutive = 0;
			}
		}
		return compressed.length() < str.length() ? compressed.toString() : str;
	}
	
	public static void main(String[] args) {
		String str = "aa";
		System.out.println(str);
		System.out.println(compress(str));
	}
}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_06_String_Compression/QuestionC.java
================================================
package Q1_06_String_Compression;

public class QuestionC {	
	public static String compress(String str) {
		int finalLength = countCompression(str);
		if (finalLength >= str.length()) return str;
		
		StringBuffer compressed = new StringBuffer(finalLength); // initialize capacity
		int countConsecutive = 0;
		for (int i = 0; i < str.length(); i++) {
			countConsecutive++;
			
			/* If next character is different than current, append this char to result.*/
			if (i + 1 >= str.length() || str.charAt(i) != str.charAt(i + 1)) {
				compressed.append(str.charAt(i));
				compressed.append(countConsecutive);
				countConsecutive = 0;
			}
		}
		return compressed.toString();
	}
	
	public static int countCompression(String str) {
		int compressedLength = 0;
		int countConsecutive = 0;
		for (int i = 0; i < str.length(); i++) {
			countConsecutive++;
			
			/* If next character is different than current, append this char to result.*/
			if (i + 1 >= str.length() || str.charAt(i) != str.charAt(i + 1)) {
				compressedLength += 1 + String.valueOf(countConsecutive).length();
				countConsecutive = 0;
			}
		}
		return compressedLength;
	}		
	
	public static void main(String[] args) {
		String str = "aa";
		System.out.println(str);
		System.out.println(compress(str));
	}
}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_06_String_Compression/Tester.java
================================================
package Q1_06_String_Compression;

public class Tester {

	public static void main(String[] args) {
		String str = "aaaaabbbbaaaabbddc";
		System.out.println(str);
		System.out.println(QuestionA.compressBad(str));
		System.out.println(QuestionB.compress(str));
		System.out.println(QuestionC.compress(str));
	}

}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_07_Rotate_Matrix/Question.java
================================================
package Q1_07_Rotate_Matrix;

import CtCILibrary.*;

public class Question {

	public static boolean rotate(int[][] matrix) {
		if (matrix.length == 0 || matrix.length != matrix[0].length) return false; // Not a square
		int n = matrix.length;
		
		for (int layer = 0; layer < n / 2; layer++) {
			int first = layer;
			int last = n - 1 - layer;
			for(int i = first; i < last; i++) {
				int offset = i - first;
				int top = matrix[first][i]; // save top

				// left -> top
				matrix[first][i] = matrix[last-offset][first]; 			

				// bottom -> left
				matrix[last-offset][first] = matrix[last][last - offset]; 

				// right -> bottom
				matrix[last][last - offset] = matrix[i][last]; 

				// top -> right
				matrix[i][last] = top; // right <- saved top
			}
		}
		return true;
	}
	
	public static void main(String[] args) {
		int[][] matrix = AssortedMethods.randomMatrix(3, 3, 0, 9);
		AssortedMethods.printMatrix(matrix);
		rotate(matrix);
		System.out.println();
		AssortedMethods.printMatrix(matrix);
	}

}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_08_Zero_Matrix/QuestionA.java
================================================
package Q1_08_Zero_Matrix;

import CtCILibrary.AssortedMethods;

public class QuestionA {
	public static void nullifyRow(int[][] matrix, int row) {
		for (int j = 0; j < matrix[0].length; j++) {
			matrix[row][j] = 0;
		}		
	}

	public static void nullifyColumn(int[][] matrix, int col) {
		for (int i = 0; i < matrix.length; i++) {
			matrix[i][col] = 0;
		}		
	}			
	
	public static void setZeros(int[][] matrix) {
		boolean[] row = new boolean[matrix.length];	
		boolean[] column = new boolean[matrix[0].length];

		// Store the row and column index with value 0
		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix[0].length;j++) {
				if (matrix[i][j] == 0) {
					row[i] = true; 
					column[j] = true;
		 		}
			}
		}
		
		// Nullify rows
		for (int i = 0; i < row.length; i++) {
			if (row[i]) {
				nullifyRow(matrix, i);
			}
		}
		
		// Nullify columns
		for (int j = 0; j < column.length; j++) {
			if (column[j]) {
				nullifyColumn(matrix, j);
			}
		}
	}	
	
	public static boolean matricesAreEqual(int[][] m1, int[][] m2) {
		if (m1.length != m2.length || m1[0].length != m2[0].length) {
			return false;
		}
		
		for (int k = 0; k < m1.length; k++) {
			for (int j = 0; j < m1[0].length; j++) {
				if (m1[k][j] != m2[k][j]) {
					return false;
				}
			}
		}	
		return true;
	}
	
	public static int[][] cloneMatrix(int[][] matrix) {
		int[][] c = new int[matrix.length][matrix[0].length];
		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix[0].length; j++) {
				c[i][j] = matrix[i][j];
			}
		}
		return c;
	}
	
	public static void main(String[] args) {
		int nrows = 10;
		int ncols = 15;
		int[][] matrix = AssortedMethods.randomMatrix(nrows, ncols, -10, 10);		

		AssortedMethods.printMatrix(matrix);
		
		setZeros(matrix);
		
		System.out.println();
		
		AssortedMethods.printMatrix(matrix);
	}
}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_08_Zero_Matrix/QuestionB.java
================================================
package Q1_08_Zero_Matrix;

import CtCILibrary.AssortedMethods;

public class QuestionB {
	public static void nullifyRow(int[][] matrix, int row) {
		for (int j = 0; j < matrix[0].length; j++) {
			matrix[row][j] = 0;
		}		
	}

	public static void nullifyColumn(int[][] matrix, int col) {
		for (int i = 0; i < matrix.length; i++) {
			matrix[i][col] = 0;
		}		
	}		
	
	public static void setZeros(int[][] matrix) {
		boolean rowHasZero = false;
		boolean colHasZero = false;		
		
		// Check if first row has a zero
		for (int j = 0; j < matrix[0].length; j++) {
			if (matrix[0][j] == 0) {
				rowHasZero = true;
				break;
			}
		}		
		
		// Check if first column has a zero
		for (int i = 0; i < matrix.length; i++) {
			if (matrix[i][0] == 0) {
				colHasZero = true;
				break;
			}
		}		
		
		// Check for zeros in the rest of the array
		for (int i = 1; i < matrix.length; i++) {
			for (int j = 1; j < matrix[0].length;j++) {
				if (matrix[i][j] == 0) {
					matrix[i][0] = 0;
					matrix[0][j] = 0;
		 		}
			}
		}		
		
		// Nullify rows based on values in first column
		for (int i = 1; i < matrix.length; i++) {
			if (matrix[i][0] == 0) {
				nullifyRow(matrix, i);
			}
		}		
		
		// Nullify columns based on values in first row
		for (int j = 1; j < matrix[0].length; j++) {
			if (matrix[0][j] == 0) {
				nullifyColumn(matrix, j);
			}
		}	
		
		// Nullify first row
		if (rowHasZero) {
			nullifyRow(matrix, 0);
		}
		
		// Nullify first column
		if (colHasZero) {
			nullifyColumn(matrix, 0);
		}
	}	
	
	public static boolean matricesAreEqual(int[][] m1, int[][] m2) {
		if (m1.length != m2.length || m1[0].length != m2[0].length) {
			return false;
		}
		
		for (int k = 0; k < m1.length; k++) {
			for (int j = 0; j < m1[0].length; j++) {
				if (m1[k][j] != m2[k][j]) {
					return false;
				}
			}
		}	
		return true;
	}
	
	public static int[][] cloneMatrix(int[][] matrix) {
		int[][] c = new int[matrix.length][matrix[0].length];
		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix[0].length; j++) {
				c[i][j] = matrix[i][j];
			}
		}
		return c;
	}
	
	public static void main(String[] args) {
		int nrows = 10;
		int ncols = 15;
		int[][] matrix = AssortedMethods.randomMatrix(nrows, ncols, -10, 10);		

		AssortedMethods.printMatrix(matrix);
		
		setZeros(matrix);
		
		System.out.println();
		
		AssortedMethods.printMatrix(matrix);
	}
}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_08_Zero_Matrix/Tester.java
================================================
package Q1_08_Zero_Matrix;

import CtCILibrary.AssortedMethods;

public class Tester {
	public static boolean matricesAreEqual(int[][] m1, int[][] m2) {
		if (m1.length != m2.length || m1[0].length != m2[0].length) {
			return false;
		}
		
		for (int k = 0; k < m1.length; k++) {
			for (int j = 0; j < m1[0].length; j++) {
				if (m1[k][j] != m2[k][j]) {
					return false;
				}
			}
		}	
		return true;
	}
	
	public static int[][] cloneMatrix(int[][] matrix) {
		int[][] c = new int[matrix.length][matrix[0].length];
		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix[0].length; j++) {
				c[i][j] = matrix[i][j];
			}
		}
		return c;
	}
	
	public static void main(String[] args) {
		int nrows = 10;
		int ncols = 15;
		int[][] matrix1 = AssortedMethods.randomMatrix(nrows, ncols, -10, 10);		
		int[][] matrix2 = cloneMatrix(matrix1);

		AssortedMethods.printMatrix(matrix1);
		
		QuestionA.setZeros(matrix1);
		QuestionB.setZeros(matrix2);
		
		System.out.println();
		
		AssortedMethods.printMatrix(matrix1);
		System.out.println();
		AssortedMethods.printMatrix(matrix2);
		
		if (matricesAreEqual(matrix1, matrix2)) {
			System.out.println("Equal");
		} else {
			System.out.println("Not Equal");
		}
	}
}


================================================
FILE: Java/Ch 01. Arrays and Strings/Q1_09_String_Rotation/Question.java
================================================
package Q1_09_String_Rotation;

public class Question {
	public static boolean isSubstring(String big, String small) {
		if (big.indexOf(small) >= 0) {
			return true;
		} else {
			return false;
		}
	}
	
	public static boolean isRotation(String s1, String s2) {
	    int len = s1.length();
	    /* check that s1 and s2 are equal length and not empty */
	    if (len == s2.length() && len > 0) { 
	    	/* concatenate s1 and s1 within new buffer */
	    	String s1s1 = s1 + s1;
	    	return isSubstring(s1s1, s2);
	    }
	    return false;
	}
	
	public static void main(String[] args) {
		String[][] pairs = {{"apple", "pleap"}, {"waterbottle", "erbottlewat"}, {"camera", "macera"}};
		for (String[] pair : pairs) {
			String word1 = pair[0];
			String word2 = pair[1];
			boolean is_rotation = isRotation(word1, word2);
			System.out.println(word1 + ", " + word2 + ": " + is_rotation);
		}
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_01_Remove_Dups/QuestionA.java
================================================
package Q2_01_Remove_Dups;

import java.util.HashSet;
import CtCILibrary.LinkedListNode;

public class QuestionA {
	public static void deleteDups(LinkedListNode n) {
		HashSet<Integer> set = new HashSet<Integer>();
		LinkedListNode previous = null;
		while (n != null) {
			if (set.contains(n.data)) {
				previous.next = n.next;
			} else {
				set.add(n.data);
				previous = n;
			}
			n = n.next;
		}
	}
	
	public static void main(String[] args) {	
		LinkedListNode first = new LinkedListNode(0, null, null); //AssortedMethods.randomLinkedList(1000, 0, 2);
		LinkedListNode head = first;
		LinkedListNode second = first;
		for (int i = 1; i < 8; i++) {
			second = new LinkedListNode(i % 2, null, null);
			first.setNext(second);
			second.setPrevious(first);
			first = second;
		}
		System.out.println(head.printForward());
		deleteDups(head);
		System.out.println(head.printForward());
	}
}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_01_Remove_Dups/QuestionB.java
================================================
package Q2_01_Remove_Dups;

import CtCILibrary.LinkedListNode;

public class QuestionB {
	public static void deleteDups(LinkedListNode head) {
		LinkedListNode current = head;
		while (current != null) {
			/* Remove all future nodes that have the same value */
			LinkedListNode runner = current;
			while (runner.next != null) { 
				if (runner.next.data == current.data) {
					runner.next = runner.next.next;
				} else {
					runner = runner.next;
				}
			}
			current = current.next;
		}
	}	
	
	public static void main(String[] args) {	
		LinkedListNode first = new LinkedListNode(0, null, null); //AssortedMethods.randomLinkedList(1000, 0, 2);
		LinkedListNode head = first;
		LinkedListNode second = first;
		for (int i = 1; i < 8; i++) {
			second = new LinkedListNode(i % 2, null, null);
			first.setNext(second);
			second.setPrevious(first);
			first = second;
		}
		System.out.println(head.printForward());
		deleteDups(head);
	}
}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_01_Remove_Dups/QuestionC.java
================================================
package Q2_01_Remove_Dups;

import CtCILibrary.LinkedListNode;

public class QuestionC {
	public static void deleteDups(LinkedListNode head) {
		if (head == null) return;
		LinkedListNode previous = head;
		LinkedListNode current = previous.next;
		while (current != null) {
			// Look backwards for dups, and remove any that you see.
			LinkedListNode runner = head;
			while (runner != current) { 
				if (runner.data == current.data) {
					LinkedListNode tmp = current.next;
					previous.next = tmp;
					current = tmp;
					/* We know we can't have more than one dup preceding
					 * our element since it would have been removed 
					 * earlier. */
				    break;
				}
				runner = runner.next;
			}
			
			/* If runner == current, then we didn't find any duplicate 
			 * elements in the previous for loop.  We then need to 
			 * increment current.  
			 * If runner != current, then we must have hit the �break� 
			 * condition, in which case we found a dup and current has
			 * already been incremented.*/
			if (runner == current) {
				previous = current;
		        current = current.next;
			}
		}
	}
	
	public static void main(String[] args) {	
		LinkedListNode first = new LinkedListNode(0, null, null); //AssortedMethods.randomLinkedList(1000, 0, 2);
		LinkedListNode head = first;
		LinkedListNode second = first;
		for (int i = 1; i < 8; i++) {
			second = new LinkedListNode(i % 2, null, null);
			first.setNext(second);
			second.setPrevious(first);
			first = second;
		}
		System.out.println(head.printForward());
		deleteDups(head);
	}
}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_01_Remove_Dups/Tester.java
================================================
package Q2_01_Remove_Dups;

import CtCILibrary.LinkedListNode;

public class Tester {

	public static void main(String[] args) {
		LinkedListNode first = new LinkedListNode(0, null, null); //AssortedMethods.randomLinkedList(1000, 0, 2);
		LinkedListNode head = first;
		LinkedListNode second = first;
		for (int i = 1; i < 8; i++) {
			second = new LinkedListNode(i % 2, null, null);
			first.setNext(second);
			second.setPrevious(first);
			first = second;
		}
		System.out.println(head.printForward());

		LinkedListNode cloneA = head.clone();
		LinkedListNode cloneB = head.clone();
		LinkedListNode cloneC = head.clone();
		QuestionA.deleteDups(cloneA);
		QuestionA.deleteDups(cloneB);
		QuestionA.deleteDups(cloneC);
		
		System.out.println(cloneA.printForward());
		System.out.println(cloneB.printForward());
		System.out.println(cloneC.printForward());
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/QuestionA.java
================================================
package Q2_02_Return_Kth_To_Last;

import CtCILibrary.*;

public class QuestionA {

	public static int printKthToLast(LinkedListNode head, int k) {
		if (head == null) {
			return 0;
		}
		int index = printKthToLast(head.next, k) + 1;
		if (index == k) {
			System.out.println(k + "th to last node is " + head.data);
		}
		return index;
	}
	
	public static void main(String[] args) {
		int[] array = {0, 1, 2, 3, 4, 5, 6};
		LinkedListNode head = AssortedMethods.createLinkedListFromArray(array);
		for (int i = 0; i <= array.length + 1; i++) {
			printKthToLast(head, i);
		}
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/QuestionB.cpp
================================================
#include <iostream>
using namespace std;

struct node {
	node * next;
	int data;
};

node* nthToLast(node* head, int k, int& i) {
	if (head == NULL) {
		return NULL;
	}
	node * nd = nthToLast(head->next, k, i);
	i = i + 1;
	if (i == k) {
		return head;
	}
	return nd;
}

node* nthToLast(node* head, int k) {
	int i = 0;
	return nthToLast(head, k, i);
}

node* createList(int count) {
	node* head = new node();
	head->data = 0;
	node* last = head;
	for (int i = 1; i < count; i++) {
		node* n = new node();
		n->data = i;
		last->next = n;
		last = n;
	}
	return head;
}

void printList(node* head) {
	while (head != NULL) {
		printf("%d", head->data);
		head = head->next;
	}
}

int main() {
	int count = 5;
	node* head = createList(count);
	printList(head);
	printf("\n");
	for (int k = 0; k <= count; k++) {
		node* n = nthToLast(head, k);
		if (n != NULL) {
			int data = n->data;
			printf("%d: ", k);
			printf("%d", n->data);
			printf("\n");
		}
	}
	return 0;
}

================================================
FILE: Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/QuestionC.java
================================================
package Q2_02_Return_Kth_To_Last;

import CtCILibrary.*;

public class QuestionC {
	public static class Index {
		public int value = 0;
	}	
	
	public static LinkedListNode kthToLast(LinkedListNode head, int k) {
		Index idx = new Index();
		return kthToLast(head, k, idx);
	}
	
	public static LinkedListNode kthToLast(LinkedListNode head, int k, Index idx) {
		if (head == null) {
			return null;
		}
		LinkedListNode node = kthToLast(head.next, k, idx);
		idx.value = idx.value + 1;
		if (idx.value == k) {
			return head;
		} 
		return node;
	}		
	
	public static void main(String[] args) {
		int[] array = {0, 1, 2, 3, 4, 5, 6};
		LinkedListNode head = AssortedMethods.createLinkedListFromArray(array);
		for (int i = 0; i <= array.length + 1; i++) {
			LinkedListNode node = kthToLast(head, i);
			String nodeValue = node == null ? "null" : "" + node.data;
			System.out.println(i + ": " + nodeValue);
		}
	}
}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/QuestionD.java
================================================
package Q2_02_Return_Kth_To_Last;

import CtCILibrary.*;

public class QuestionD {
	
	public static LinkedListNode nthToLast(LinkedListNode head, int k) {
		LinkedListNode p1 = head;
		LinkedListNode p2 = head;
		
		/* Move p1 k nodes into the list.*/
		for (int i = 0; i < k; i++) {
			if (p1 == null) return null; // Out of bounds
			p1 = p1.next;
		}
		
		/* Move them at the same pace. When p1 hits the end, 
		 * p2 will be at the right element. */
		while (p1 != null) {
			p1 = p1.next;
			p2 = p2.next;
	  	}
	  	return p2;
	}
	
	public static void main(String[] args) {
		int[] array = {0, 1, 2, 3};
		LinkedListNode head = AssortedMethods.createLinkedListFromArray(array);
		for (int i = 0; i <= array.length + 1; i++) {
			LinkedListNode node = nthToLast(head, i);
			String nodeValue = node == null ? "null" : "" + node.data;
			System.out.println(i + ": " + nodeValue);
		}
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/Tester.java
================================================
package Q2_02_Return_Kth_To_Last;

import CtCILibrary.AssortedMethods;

public class Tester {

	
	public static void main(String[] args) {

	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_03_Delete_Middle_Node/Question.java
================================================
package Q2_03_Delete_Middle_Node;

import CtCILibrary.AssortedMethods;
import CtCILibrary.LinkedListNode;

public class Question {

	public static boolean deleteNode(LinkedListNode n) {
		if (n == null || n.next == null) {
			return false; // Failure
		} 
		LinkedListNode next = n.next; 
		n.data = next.data; 
		n.next = next.next; 
		return true;
	}
	
	public static void main(String[] args) {
		LinkedListNode head = AssortedMethods.randomLinkedList(10, 0, 10);
		System.out.println(head.printForward());
		deleteNode(head.next.next.next.next); // delete node 4
		System.out.println(head.printForward());
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_04_Partition/Question.java
================================================
package Q2_04_Partition;

import CtCILibrary.LinkedListNode;

public class Question {

	public static LinkedListNode partition(LinkedListNode node, int x) {
		LinkedListNode beforeStart = null;
		LinkedListNode beforeEnd = null;
		LinkedListNode afterStart = null;
		LinkedListNode afterEnd = null;
		
		/* Partition list */
		while (node != null) {
			LinkedListNode next = node.next;
			node.next = null;
			if (node.data < x) {
				if (beforeStart == null) {
					beforeStart = node;
					beforeEnd = beforeStart;
				} else {
					beforeEnd.next = node;
					beforeEnd = node;
				}
			} else {
				if (afterStart == null) {
					afterStart = node;
					afterEnd = afterStart;
				} else {
					afterEnd.next = node;
					afterEnd = node;
				}
			}	
			node = next;
		}
		
		/* Merge before list and after list */
		if (beforeStart == null) {
			return afterStart;
		}
		
		beforeEnd.next = afterStart;
		return beforeStart;
	}
	
	public static void main(String[] args) {
		/* Create linked list */
		int[] vals = {33,9,2,3,10,10389,838,874578,5};
		LinkedListNode head = new LinkedListNode(vals[0], null, null);
		LinkedListNode current = head;
		for (int i = 1; i < vals.length; i++) {
			current = new LinkedListNode(vals[i], null, current);
		}
		System.out.println(head.printForward());
		
		/* Partition */
		LinkedListNode h = partition(head, 3);
		
		/* Print Result */
		System.out.println(h.printForward());
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_04_Partition/QuestionB.java
================================================
package Q2_04_Partition;

import CtCILibrary.LinkedListNode;

public class QuestionB {

	public static LinkedListNode partition(LinkedListNode node, int x) {
		LinkedListNode beforeStart = null;
		LinkedListNode afterStart = null;
		
		/* Partition list */
		while (node != null) {
			LinkedListNode next = node.next;
			if (node.data < x) {
				/* Insert node into start of before list */
				node.next = beforeStart;
				beforeStart = node;	
			} else {
				/* Insert node into front of after list */
				node.next = afterStart;
				afterStart = node;
			}	
			node = next;
		}
		
		/* Merge before list and after list */
		if (beforeStart == null) {
			return afterStart;
		}
		
		LinkedListNode head = beforeStart;
		while (beforeStart.next != null) {
			beforeStart = beforeStart.next;
		}
		beforeStart.next = afterStart;
		return head;
	}
	
	public static void main(String[] args) {
		int length = 20;
		LinkedListNode[] nodes = new LinkedListNode[length];
		for (int i = 0; i < length; i++) {
			nodes[i] = new LinkedListNode(i >= length / 2 ? length - i - 1 : i, null, null);
		}
		
		for (int i = 0; i < length; i++) {
			if (i < length - 1) {
				nodes[i].setNext(nodes[i + 1]);
			}
			if (i > 0) {
				nodes[i].setPrevious(nodes[i - 1]);
			}
		}
		
		LinkedListNode head = nodes[0];
		System.out.println(head.printForward());
		
		LinkedListNode h = partition(head, 7);
		System.out.println(h.printForward());
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_04_Partition/QuestionC.java
================================================
package Q2_04_Partition;

import CtCILibrary.LinkedListNode;

public class QuestionC {

	public static LinkedListNode partition(LinkedListNode node, int x) {
		LinkedListNode head = node;
		LinkedListNode tail = node;
		
		/* Partition list */
		while (node != null) {
			LinkedListNode next = node.next;
			if (node.data < x) {
				/* Insert node at head. */
				node.next = head;
				head = node;
			} else {
				/* Insert node at tail. */
				tail.next = node;
				tail = node;
			}	
			node = next;
		}
		tail.next = null;
		
		return head;
	}
	
	public static void main(String[] args) {
		int length = 20;
		LinkedListNode[] nodes = new LinkedListNode[length];
		for (int i = 0; i < length; i++) {
			nodes[i] = new LinkedListNode(i >= length / 2 ? length - i - 1 : i, null, null);
		}
		
		for (int i = 0; i < length; i++) {
			if (i < length - 1) {
				nodes[i].setNext(nodes[i + 1]);
			}
			if (i > 0) {
				nodes[i].setPrevious(nodes[i - 1]);
			}
		}
		
		LinkedListNode head = nodes[0];
		System.out.println(head.printForward());
		
		LinkedListNode h = partition(head, 8);
		System.out.println(h.printForward());
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_04_Partition/Tester.java
================================================
package Q2_04_Partition;

import CtCILibrary.LinkedListNode;

public class Tester {
	
	public static LinkedListNode createLinkedList() {
		/* Create linked list */
		int[] vals = {3, 5, 8, 5, 10, 2, 1};
		LinkedListNode head = new LinkedListNode(vals[0], null, null);
		LinkedListNode current = head;
		for (int i = 1; i < vals.length; i++) {
			current = new LinkedListNode(vals[i], null, current);
		}
		return head;
	}

	public static void main(String[] args) {
		System.out.println(createLinkedList().printForward());
		
		/* Partition */
		LinkedListNode hA = Question.partition(createLinkedList(), 5);
		LinkedListNode hB = QuestionB.partition(createLinkedList(), 5);
		LinkedListNode hC = QuestionC.partition(createLinkedList(), 5);
		
		/* Print Result */
		System.out.println(hA.printForward());
		System.out.println(hB.printForward());
		System.out.println(hC.printForward());
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_05_Sum_Lists/PartialSum.java
================================================
package Q2_05_Sum_Lists;

import CtCILibrary.LinkedListNode;

public class PartialSum {
	public LinkedListNode sum = null;
	public int carry = 0;
}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_05_Sum_Lists/QuestionA.java
================================================
package Q2_05_Sum_Lists;


import CtCILibrary.LinkedListNode;

public class QuestionA {
	private static LinkedListNode addLists(LinkedListNode l1, LinkedListNode l2) {
		return addLists(l1, l2, 0);
	}
	
	private static LinkedListNode addLists(LinkedListNode l1, LinkedListNode l2, int carry) {
		if (l1 == null && l2 == null && carry == 0) {
             return null;
		}
		
		LinkedListNode result = new LinkedListNode();
		int value = carry;
		if (l1 != null) {
			value += l1.data;
		}
		if (l2 != null) {
			value += l2.data;
		}
		result.data = value % 10;
		if (l1 != null || l2 != null) {
			LinkedListNode more = addLists(l1 == null ? null : l1.next, 
										   l2 == null ? null : l2.next, 
										   value >= 10 ? 1 : 0);
			result.setNext(more);
		}
		return result;
	}
	
	public static int linkedListToInt(LinkedListNode node) {
		int value = 0;
		if (node.next != null) {
			value = 10 * linkedListToInt(node.next);
		}
		return value + node.data;
	}	
	
	public static void main(String[] args) {
		LinkedListNode lA1 = new LinkedListNode(9, null, null);
		LinkedListNode lA2 = new LinkedListNode(9, null, lA1);
		LinkedListNode lA3 = new LinkedListNode(9, null, lA2);
		
		LinkedListNode lB1 = new LinkedListNode(1, null, null);
		LinkedListNode lB2 = new LinkedListNode(0, null, lB1);
		LinkedListNode lB3 = new LinkedListNode(0, null, lB2);	
		
		LinkedListNode list3 = addLists(lA1, lB1);
		
		System.out.println("  " + lA1.printForward());		
		System.out.println("+ " + lB1.printForward());			
		System.out.println("= " + list3.printForward());	
		
		int l1 = linkedListToInt(lA1);
		int l2 = linkedListToInt(lB1);
		int l3 = linkedListToInt(list3);
		
		System.out.print(l1 + " + " + l2 + " = " + l3 + "\n");
		System.out.print(l1 + " + " + l2 + " = " + (l1 + l2));		
	}
}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_05_Sum_Lists/QuestionB.java
================================================
package Q2_05_Sum_Lists;
import CtCILibrary.LinkedListNode;

public class QuestionB {
	private static int length(LinkedListNode l) {
		if (l == null) {
			return 0;
		} else {
			return 1 + length(l.next);
		}
	}
	
	private static PartialSum addListsHelper(LinkedListNode l1, LinkedListNode l2) {
		if (l1 == null && l2 == null) {
			PartialSum sum = new PartialSum();
			return sum;
		}
		PartialSum sum = addListsHelper(l1.next, l2.next);
		int val = sum.carry + l1.data + l2.data;
		LinkedListNode full_result = insertBefore(sum.sum, val % 10);
		sum.sum = full_result;
		sum.carry = val / 10;
		return sum;
	}
	
	private static LinkedListNode addLists(LinkedListNode l1, LinkedListNode l2) {
		int len1 = length(l1);
		int len2 = length(l2);
		if (len1 < len2) {
			l1 = padList(l1, len2 - len1);
		} else {
			l2 = padList(l2, len1 - len2);
		}
		PartialSum sum = addListsHelper(l1, l2);
		if (sum.carry == 0) {
			return sum.sum;
		} else {
			LinkedListNode result = insertBefore(sum.sum, sum.carry);
			return result;
		}
	}	
	
	private static LinkedListNode padList(LinkedListNode l, int padding) {
		LinkedListNode head = l;
		for (int i = 0; i < padding; i++) {
			head = insertBefore(head, 0);
		}
		return head;
	}
	
	private static LinkedListNode insertBefore(LinkedListNode list, int data) {
		LinkedListNode node = new LinkedListNode(data);
		if (list != null) {
			node.next = list;
		}
		return node;
	}
	
	public static int linkedListToInt(LinkedListNode node) {
		int value = 0;
		while (node != null) {
			value = value * 10 + node.data;
			node = node.next;
		}
		return value;
	}	
	
	public static void main(String[] args) {
		LinkedListNode lA1 = new LinkedListNode(3, null, null);
		LinkedListNode lA2 = new LinkedListNode(1, null, lA1);
		
		LinkedListNode lB1 = new LinkedListNode(5, null, null);
		LinkedListNode lB2 = new LinkedListNode(9, null, lB1);
		LinkedListNode lB3 = new LinkedListNode(1, null, lB2);	
		
		LinkedListNode list3 = addLists(lA1, lB1);
		
		System.out.println("  " + lA1.printForward());		
		System.out.println("+ " + lB1.printForward());			
		System.out.println("= " + list3.printForward());	
		
		int l1 = linkedListToInt(lA1);
		int l2 = linkedListToInt(lB1);
		int l3 = linkedListToInt(list3);
		
		System.out.print(l1 + " + " + l2 + " = " + l3 + "\n");
		System.out.print(l1 + " + " + l2 + " = " + (l1 + l2));		
	}
}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_06_Palindrome/QuestionA.java
================================================
package Q2_06_Palindrome;

import CtCILibrary.LinkedListNode;

public class QuestionA {
	public static boolean isPalindrome(LinkedListNode head) {
		LinkedListNode reversed = reverseAndClone(head);
		return isEqual(head, reversed);
	}
		
	public static LinkedListNode reverseAndClone(LinkedListNode node) {
		LinkedListNode head = null;
		while (node != null) {
			LinkedListNode n = new LinkedListNode(node.data); // Clone
			n.next = head;
			head = n;
			node = node.next;
		}
		return head;
	}	
		
	public static boolean isEqual(LinkedListNode one, LinkedListNode two) {
		while (one != null && two != null) {
			if (one.data != two.data) {
				return false;
			}
			one = one.next;
			two = two.next;
		}
		return one == null && two == null;
	}
	
	public static void main(String[] args) {
		int length = 9;
		LinkedListNode[] nodes = new LinkedListNode[length];
		for (int i = 0; i < length; i++) {
			nodes[i] = new LinkedListNode(i >= length / 2 ? length - i - 1 : i, null, null);
		}
		
		for (int i = 0; i < length; i++) {
			if (i < length - 1) {
				nodes[i].setNext(nodes[i + 1]);
			}
			if (i > 0) {
				nodes[i].setPrevious(nodes[i - 1]);
			}
		}
		// nodes[length - 2].data = 9; // Uncomment to ruin palindrome
		
		LinkedListNode head = nodes[0];
		System.out.println(head.printForward());
		System.out.println(isPalindrome(head));
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_06_Palindrome/QuestionB.java
================================================
package Q2_06_Palindrome;

import CtCILibrary.LinkedListNode;

import java.util.Stack;

public class QuestionB {
	public static boolean isPalindrome(LinkedListNode head) {
		LinkedListNode fast = head;
		LinkedListNode slow = head;
		
		Stack<Integer> stack = new Stack<Integer>();
		
		while (fast != null && fast.next != null) {
			stack.push(slow.data);
			slow = slow.next;
			fast = fast.next.next;			
		}
		
		/* Has odd number of elements, so skip the middle */
		if (fast != null) { 
			slow = slow.next;
		}
		
		while (slow != null) {
			int top = stack.pop().intValue();
			if (top != slow.data) {
				return false;
			}
			slow = slow.next;
		}
		return true;
	}
	
	public static void main(String[] args) {
		int length = 9;
		LinkedListNode[] nodes = new LinkedListNode[length];
		for (int i = 0; i < length; i++) {
			nodes[i] = new LinkedListNode(i >= length / 2 ? length - i - 1 : i, null, null);
		}
		
		for (int i = 0; i < length; i++) {
			if (i < length - 1) {
				nodes[i].setNext(nodes[i + 1]);
			}
			if (i > 0) {
				nodes[i].setPrevious(nodes[i - 1]);
			}
		}
		//nodes[length - 2].data = 9; // Uncomment to ruin palindrome
		
		LinkedListNode head = nodes[0];
		System.out.println(head.printForward());
		System.out.println(isPalindrome(head));
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_06_Palindrome/QuestionC.java
================================================
package Q2_06_Palindrome;

import CtCILibrary.LinkedListNode;

public class QuestionC {
	public static class Result {
		public LinkedListNode node;
		public boolean result;
		public Result(LinkedListNode n, boolean res) {
			node = n;
			result = res;
		}
	}

	public static Result isPalindromeRecurse(LinkedListNode head, int length) {
		if (head == null || length <= 0) { // Even number of nodes
			return new Result(head, true);
		} else if (length == 1) { // Odd number of nodes
			return new Result(head.next, true);
		} 
		
		/* Recurse on sublist. */
		Result res = isPalindromeRecurse(head.next, length - 2);
		
		/* If child calls are not a palindrome, pass back up 
		 * a failure. */
		if (!res.result || res.node == null) {
			return res;
		} 
		
		/* Check if matches corresponding node on other side. */
		res.result = (head.data == res.node.data); 
		
		/* Return corresponding node. */
		res.node = res.node.next;
		
		return res;
	}
	
	public static int lengthOfList(LinkedListNode n) {
		int size = 0;
		while (n != null) {
			size++;
			n = n.next;
		}
		return size;
	}
	
	public static boolean isPalindrome(LinkedListNode head) {
		int length = lengthOfList(head);
		Result p = isPalindromeRecurse(head, length);
		return p.result;
	}
	
	public static void main(String[] args) {
		int length = 9;
		LinkedListNode[] nodes = new LinkedListNode[length];
		for (int i = 0; i < length; i++) {
			nodes[i] = new LinkedListNode(i >= length / 2 ? length - i - 1 : i, null, null);
		}
		
		for (int i = 0; i < length; i++) {
			if (i < length - 1) {
				nodes[i].setNext(nodes[i + 1]);
			}
			if (i > 0) {
				nodes[i].setPrevious(nodes[i - 1]);
			}
		}
		//nodes[length - 2].data = 9; // Uncomment to ruin palindrome
		
		LinkedListNode head = nodes[0];
		System.out.println(head.printForward());
		System.out.println(isPalindrome(head));
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_06_Palindrome/Tester.java
================================================
package Q2_06_Palindrome;

import CtCILibrary.LinkedListNode;

public class Tester {
	
	public static void main(String[] args) {
		int max = 11;
		for (int length = 1; length < max; length++) {
			LinkedListNode[] nodes = new LinkedListNode[length];
			for (int i = 0; i < length; i++) {
				nodes[i] = new LinkedListNode(i >= length / 2 ? length - i - 1 : i, null, null);
			}
			
			for (int i = 0; i < length; i++) {
				if (i < length - 1) {
					nodes[i].setNext(nodes[i + 1]);
				}
				if (i > 0) {
					nodes[i].setPrevious(nodes[i - 1]);
				}
			}
			for (int i = -1; i < length; i++) {
				if (i >= 0) {
					nodes[i].data++; // Ruin palindrome
				}
				
				LinkedListNode head = nodes[0];
				System.out.println(head.printForward());
				boolean resultA = QuestionA.isPalindrome(head);
				boolean resultB = QuestionB.isPalindrome(head);
				boolean resultC = QuestionC.isPalindrome(head);
				System.out.println("A: " + resultA);
				System.out.println("B: " + resultB);
				System.out.println("C: " + resultC);
				if (resultA != resultB || resultB != resultC) {
					System.out.println("ERROR");
					length = max;
					break;
				}
				if (i >= 0) {
					nodes[i].data--;
				}
			}
		}
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_07_Intersection/Question.java
================================================
package Q2_07_Intersection;

import CtCILibrary.AssortedMethods;
import CtCILibrary.LinkedListNode;

public class Question {

	public static class Result {
		public LinkedListNode tail;
		public int size;
		public Result(LinkedListNode tail, int size) {
			this.tail = tail;
			this.size = size;
		}
	}
	
	public static Result getTailAndSize(LinkedListNode list) {
		if (list == null) return null;
		
		int size = 1;
		LinkedListNode current = list;
		while (current.next != null) {
			size++;
			current = current.next;
		}
		return new Result(current, size);
	}
	
	public static LinkedListNode getKthNode(LinkedListNode head, int k) {
		LinkedListNode current = head;
		while (k > 0 && current != null) {
			current = current.next;
			k--;
		}
		return current;
	}
	
	public static LinkedListNode findIntersection(LinkedListNode list1, LinkedListNode list2) {
		if (list1 == null || list2 == null) return null;
		
		/* Get tail and sizes. */
		Result result1 = getTailAndSize(list1);
		Result result2 = getTailAndSize(list2);
		
		/* If different tail nodes, then there's no intersection. */
		if (result1.tail != result2.tail) {
			return null;
		}
		
		/* Set pointers to the start of each linked list. */
		LinkedListNode shorter = result1.size < result2.size ? list1 : list2;
		LinkedListNode longer = result1.size < result2.size ? list2 : list1;
		
		/* Advance the pointer for the longer linked list by the difference in lengths. */
		longer = getKthNode(longer, Math.abs(result1.size - result2.size));
		
		/* Move both pointers until you have a collision. */
		while (shorter != longer) {
			shorter = shorter.next;
			longer = longer.next;
		}
		
		/* Return either one. */
		return longer; 
	}
	
	public static void main(String[] args) {
		/* Create linked list */
		int[] vals = {-1, -2, 0, 1, 2, 3, 4, 5, 6, 7, 8};
		LinkedListNode list1 = AssortedMethods.createLinkedListFromArray(vals);
		
		int[] vals2 = {12, 14, 15};
		LinkedListNode list2 = AssortedMethods.createLinkedListFromArray(vals2);
		
		list2.next.next = list1.next.next.next.next;
		
		System.out.println(list1.printForward());
		System.out.println(list2.printForward());
		
		
		LinkedListNode intersection = findIntersection(list1, list2);
		
		System.out.println(intersection.printForward());
	}

}


================================================
FILE: Java/Ch 02. Linked Lists/Q2_08_Loop_Detection/Question.java
================================================
package Q2_08_Loop_Detection;

import CtCILibrary.LinkedListNode;

public class Question {

	public static LinkedListNode FindBeginning(LinkedListNode head) {
		LinkedListNode slow = head;
		LinkedListNode fast = head; 
		
		// Find meeting point
		while (fast != null && fast.next != null) { 
			slow = slow.next; 
			fast = fast.next.next;
			if (slow == fast) {
				break;
			}
		}

		// Error check - there is no meeting point, and therefore no loop
		if (fast == null || fast.next == null) {
			return null;
		}

		/* Move slow to Head. Keep fast at Meeting Point. Each are k steps
		/* from the Loop Start. If they move at the same pace, they must
		 * meet at Loop Start. */
		slow = head; 
		while (slow != fast) { 
			slow = slow.next; 
			fast = fast.next; 
		}
		
		// Both now point to the start of the loop.
		return fast;
	}
	
	public static void main(String[] args) {
		int list_length = 100;
		int k = 10;
		
		// Create linked list
		LinkedListNode[] nodes = new LinkedListNode[list_length];
		for (int i = 0; i < list_length; i++) {
			nodes[i] = new LinkedListNode(i, null, i > 0 ? nodes[i - 1] : null);
		}
		
		// Create loop;
		nodes[list_length - 1].next = nodes[list_length - k];
		
		LinkedListNode loop = FindBeginning(nodes[0]);
		if (loop == null) {
			System.out.println("No Cycle.");
		} else {
			System.out.println(loop.data);
		}
	}

}


================================================
FILE: Java/Ch 03. Stacks and Queues/Introduction/MyQueue.java
================================================
package Introduction;

import java.util.NoSuchElementException;

public class MyQueue<T> {
	private static class QueueNode<T> {
		private T data;
		private QueueNode<T> next;
		
		public QueueNode(T data) {
			this.data = data;
		}
	}
	
	private QueueNode<T> first;
	private QueueNode<T> last;

	public void add(T item) { 
		QueueNode<T> t = new QueueNode<T>(item);
		if (last != null) {
			last.next = t;
		}
		last = t;
		if (first == null) {
			first = last;
		}
	} 

	public T remove() {
		if (first == null) throw new NoSuchElementException();
		T data = first.data;
		first = first.next;
		if (first == null) {
			last = null;
		}
		return data;
	}
	
	public T peek() {
		if (first == null) throw new NoSuchElementException();
		return first.data;
	}
	
	public boolean isEmpty() {
		return first == null;
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Introduction/MyStack.java
================================================
package Introduction;

import java.util.EmptyStackException;

public class MyStack<T> {
	private static class StackNode<T> {
		private T data;
		private StackNode<T> next;
		
		public StackNode(T data) {
			this.data = data;
		}
		
		public T getData() {
			return data;
		}
	}
	
	private StackNode<T> top;

	public T pop() {
		if (top == null) throw new EmptyStackException();
		T item = top.getData();
		top = top.next;
		return item;
	}

	public void push(T item) { 
		StackNode<T> t = new StackNode<T>(item);
		t.next = top;
		top = t;
	} 

	public T peek() {
		if (top == null) throw new EmptyStackException();
		return top.data;
	}
	
	public boolean isEmpty() {
		return top == null;
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Introduction/QueueTester.java
================================================
package Introduction;

import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;

import CtCILibrary.AssortedMethods;

public class QueueTester {

	public static void main(String[] args) {
		int[] array = AssortedMethods.randomArray(100, -100, 100);
		MyQueue<Integer> queue1 = new MyQueue<Integer>();		
		Queue<Integer> queue2 = new LinkedList<Integer>();
		
		for (int a : array) {
			if (a < 0) {
				int top1, top2;
				try {
					top1 = queue1.remove();
				} catch (NoSuchElementException ex) {
					top1 = Integer.MIN_VALUE;
				}
				try {
					top2 = queue2.remove();
				} catch (NoSuchElementException ex) {
					top2 = Integer.MIN_VALUE;
				}
				if (top1 != top2) {
					System.out.println("ERROR: mismatching tails");
				} else {
					System.out.println("SUCCESS: matching tails: " + top1);
				}
			} else {
				queue1.add(a);
				queue2.add(a);
			}
		}
		
		while (!queue1.isEmpty() || !queue2.isEmpty()) {
			int top1, top2;
			try {
				top1 = queue1.remove();
			} catch (NoSuchElementException ex) {
				top1 = Integer.MIN_VALUE;
			}
			try {
				top2 = queue2.remove();
			} catch (NoSuchElementException ex) {
				top2 = Integer.MIN_VALUE;
			}
			if (top1 != top2) {
				System.out.println("ERROR: mismatching tails");
			} else {
				System.out.println("SUCCESS: matching tails: " + top1);
			}
		}
	}

}


================================================
FILE: Java/Ch 03. Stacks and Queues/Introduction/StackTester.java
================================================
package Introduction;

import java.util.EmptyStackException;
import java.util.Stack;

import CtCILibrary.AssortedMethods;

public class StackTester {

	public static void main(String[] args) {
		int[] array = AssortedMethods.randomArray(100, -100, 100);
		MyStack<Integer> stack1 = new MyStack<Integer>();		
		Stack<Integer> stack2 = new Stack<Integer>();
		
		for (int a : array) {
			if (a < 0) {
				int top1, top2;
				try {
					top1 = stack1.pop();
				} catch (EmptyStackException ex) {
					top1 = Integer.MIN_VALUE;
				}
				try {
					top2 = stack2.pop();
				} catch (EmptyStackException ex) {
					top2 = Integer.MIN_VALUE;
				}
				if (top1 != top2) {
					System.out.println("ERROR: mismatching tops");
				} else {
					System.out.println("SUCCESS: matching tops: " + top1);
				}
			} else {
				stack1.push(a);
				stack2.push(a);
			}
		}
		
		while (!stack1.isEmpty() || !stack2.isEmpty()) {
			int top1, top2;
			try {
				top1 = stack1.pop();
			} catch (EmptyStackException ex) {
				top1 = Integer.MIN_VALUE;
			}
			try {
				top2 = stack2.pop();
			} catch (EmptyStackException ex) {
				top2 = Integer.MIN_VALUE;
			}
			if (top1 != top2) {
				System.out.println("ERROR: mismatching tops");
			} else {
				System.out.println("SUCCESS: matching tops: " + top1);
			}
		}
	}

}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/FixedMultiStack.java
================================================
package Q3_01_Three_in_One;

import java.util.EmptyStackException;

import CtCILibrary.AssortedMethods;

public class FixedMultiStack {
	private int numberOfStacks = 3;
	private int stackCapacity;
	private int[] values;
	private int[] sizes;
	
	public FixedMultiStack(int stackSize) {
		stackCapacity = stackSize;
		values = new int[stackSize * numberOfStacks];
		sizes = new int[numberOfStacks];
	}

	/* Push value onto stack. */
	public void push(int stackNum, int value) throws FullStackException {
		/* Check that we have space for the next element */
		if (isFull(stackNum)) { 
			throw new FullStackException();
		}
		
		/* Increment stack pointer and then update top value. */		
		sizes[stackNum]++;
		values[indexOfTop(stackNum)] = value;	
	}

	/* Pop item from top stack. */
	public int pop(int stackNum) {
		if (isEmpty(stackNum)) {
			throw new EmptyStackException();
		}
		
		int topIndex = indexOfTop(stackNum);
		int value = values[topIndex]; // Get top
		values[topIndex] = 0; // Clear 
		sizes[stackNum]--; // Shrink
		return value;
	}

	/* Return top element. */
	public int peek(int stackNum) {
		if (isEmpty(stackNum)) {
			throw new EmptyStackException();
		}		
		return values[indexOfTop(stackNum)];
	}

	/* Return if stack is empty. */
	public boolean isEmpty(int stackNum) {
		return sizes[stackNum] == 0;
	}
	
	/* Return if stack is full. */
	public boolean isFull(int stackNum) {
		return sizes[stackNum] == stackCapacity;
	}
	
	/* Returns index of the top of the stack. */
	private int indexOfTop(int stackNum) {
		int offset = stackNum * stackCapacity;
		int size = sizes[stackNum];
		return offset + size - 1;
	}	
	
	public int[] getValues() {
		return values;
	}
	
	public int[] getStackValues(int stackNum) {
		int[] items = new int[sizes[stackNum]];
		for (int i = 0; i < items.length; i++) {
			items[i] = values[stackNum * stackCapacity + i];
		}
		return items;
	}
	
	public String stackToString(int stackNum) {
		int[] items = getStackValues(stackNum);
		return stackNum + ": " + AssortedMethods.arrayToString(items);
	}	
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/FullStackException.java
================================================
package Q3_01_Three_in_One;

public class FullStackException extends Exception {
	private static final long serialVersionUID = 1L;

	public FullStackException(){
        super();
    }

    public FullStackException(String message){
        super(message);
    }
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/MultiStack.java
================================================
package Q3_01_Three_in_One;

import java.util.EmptyStackException;

import CtCILibrary.AssortedMethods;

public class MultiStack {
	/* StackInfo is a simple class that holds a set of data about 
	 * each stack. It does not hold the actual items in the stack. 
	 * We could have done this with just a bunch of individual 
	 * variables, but that’s messy and doesn’t gain us much. */
	private class StackInfo {
		public int start, size, capacity;
		public StackInfo(int start, int capacity) {
			this.start = start;
			this.capacity = capacity;
		}
		
		/* Check if an index on the full array is within the stack
		 * boundaries. The stack can wrap around to the start of 
		 * the array. */
		public boolean isWithinStackCapacity(int index) {
			/* If outside of bounds of array, return false. */
			if (index < 0 || index >= values.length) {
				return false;
			}
			
			/* If index wraps around, adjust it. */
			int contiguousIndex = index < start ? index + values.length : index;
			int end = start + capacity;
			return start <= contiguousIndex && contiguousIndex < end;
		}
		
		public int lastCapacityIndex() {
			return adjustIndex(start + capacity - 1);
		}
		
		public int lastElementIndex() {
			return adjustIndex(start + size - 1);
		}		
		
		public boolean isFull() {
			return size == capacity;
		}
		
		public boolean isEmpty() {
			return size == 0;
		}
	}
	
	private StackInfo[] info;
	private int[] values;
	
	public MultiStack(int numberOfStacks, int defaultSize) {
		/* Create metadata for all the stacks. */
		info = new StackInfo[numberOfStacks];
		for (int i = 0; i < numberOfStacks; i++) {
			info[i] = new StackInfo(defaultSize * i, defaultSize);
		}
		values = new int[numberOfStacks * defaultSize];
	}	
	
	/* Returns the number of items actually present in stack. */
	public int numberOfElements() {
		int size = 0;
		for (StackInfo sd : info) {
			size += sd.size;
		}
		return size;
	}
	
	/* Returns true is all the stacks are full. */
	public boolean allStacksAreFull() {
		return numberOfElements() == values.length;
	}
	
	/* Adjust index to be within the range of 0 -> length - 1. */
	private int adjustIndex(int index) {
		/* Java's mod operator can return neg values. For example,
		 * (-11 % 5) will return -1, not 4. We actually want the 
		 * value to be 4 (since we're wrapping around the index). 
		 */
		int max = values.length;
		return ((index % max) + max) % max;
	}
	
	/* Get index after this index, adjusted for wrap around. */
	private int nextIndex(int index) {
		return adjustIndex(index + 1);
	}
	
	/* Get index before this index, adjusted for wrap around. */
	private int previousIndex(int index) {
		return adjustIndex(index - 1);
	}
	
	/* Shift items in stack over by one element. If we have 
	 * available capacity, then we'll end up shrinking the stack 
	 * by one element. If we don't have available capacity, then
	 * we'll need to shift the next stack over too. */
	private void shift(int stackNum) {
		System.out.println("/// Shifting " + stackNum);
		StackInfo stack = info[stackNum];
		
		/* If this stack is at its full capacity, then you need
		 * to move the next stack over by one element. This stack
		 * can now claim the freed index. */
		if (stack.size >= stack.capacity) {
			int nextStack = (stackNum + 1) % info.length;
			shift(nextStack); 
			stack.capacity++; // claim index that next stack lost
		}
		
		/* Shift all elements in stack over by one. */
		int index = stack.lastCapacityIndex();
		while (stack.isWithinStackCapacity(index)) {
			values[index] = values[previousIndex(index)];
			index = previousIndex(index);
		}
		
		/* Adjust stack data. */
		values[stack.start] = 0; // Clear item
		stack.start = nextIndex(stack.start); // move start
		stack.capacity--; // Shrink capacity
	}
	
	/* Expand stack by shifting over other stacks */
	private void expand(int stackNum) {
		System.out.println("/// Expanding stack " + stackNum);
		
		shift((stackNum + 1) % info.length);
		info[stackNum].capacity++;
	}

	/* Push value onto stack num, shifting/expanding stacks as 
	 * necessary. Throws exception if all stacks are full. */
	public void push(int stackNum, int value) throws FullStackException {
		System.out.println("/// Pushing stack " + stackNum + ": " + value);
		if (allStacksAreFull()) {
			throw new FullStackException();
		}
		
		/* If this stack is full, expand it. */
		StackInfo stack = info[stackNum];
		if (stack.isFull()) {
			expand(stackNum);
		}
		
		/* Find the index of the top element in the array + 1, 
		 * and increment the stack pointer */	
		stack.size++;	
		values[stack.lastElementIndex()] = value;	
	}

	/* Remove value from stack. */
	public int pop(int stackNum) throws Exception {
		System.out.println("/// Popping stack " + stackNum);
		StackInfo stack = info[stackNum];		
		if (stack.isEmpty()) {
			throw new EmptyStackException();
		}

		/* Remove last element. */
		int value = values[stack.lastElementIndex()];
		values[stack.lastElementIndex()] = 0; // Clear item
		stack.size--; // Shrink size
		return value;
	}

	/* Get top element of stack.*/
	public int peek(int stackNum) {
		StackInfo stack = info[stackNum];			
		return values[stack.lastElementIndex()];
	}
	
	public int[] getValues() {
		return values;
	}
	
	public int[] getStackValues(int stackNum) {
		StackInfo stack = info[stackNum];
		int[] items = new int[stack.size];
		for (int i = 0; i < items.length; i++) {
			items[i] = values[adjustIndex(stack.start + i)];
		}
		return items;
	}
	
	public String stackToString(int stackNum) {
		int[] items = getStackValues(stackNum);
		return stackNum + ": " + AssortedMethods.arrayToString(items);
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/QuestionA.java
================================================
package Q3_01_Three_in_One;

import CtCILibrary.AssortedMethods;

public class QuestionA {
	public static void printStacks(FixedMultiStack stacks) {
		System.out.println(AssortedMethods.arrayToString(stacks.getValues()));
	}
	
	public static void main(String [] args) throws Exception  {
		FixedMultiStack stacks = new FixedMultiStack(4);
		printStacks(stacks);
		stacks.push(0, 10);
		printStacks(stacks);
		stacks.push(1, 20);
		printStacks(stacks);
		stacks.push(2, 30);
		printStacks(stacks);
		
		stacks.push(1, 21);
		printStacks(stacks);
		stacks.push(0, 11);
		printStacks(stacks);
		stacks.push(0, 12);
		printStacks(stacks);
		
		stacks.pop(0);
		printStacks(stacks);
		
		stacks.push(2, 31);
		printStacks(stacks);
		
		stacks.push(0, 13);
		printStacks(stacks);
		stacks.push(1, 22);
		printStacks(stacks);
		
		stacks.push(2, 31);
		printStacks(stacks);
		stacks.push(2, 32);
		printStacks(stacks);
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/QuestionB.java
================================================
package Q3_01_Three_in_One;

import CtCILibrary.AssortedMethods;

public class QuestionB {
	public static void printStacks(MultiStack stacks) {
		//System.out.println(stacks.stackToString(0));
		//System.out.println(stacks.stackToString(1));
		//System.out.println(stacks.stackToString(2));
		System.out.println(AssortedMethods.arrayToString(stacks.getValues()));
	}
	
	public static void main(String [] args) throws Exception  {	
		MultiStack stacks = new MultiStack(3, 4);
		printStacks(stacks);
		stacks.push(0, 10);
		printStacks(stacks);
		stacks.push(1, 20);
		printStacks(stacks);
		stacks.push(2, 30);
		printStacks(stacks);
		
		stacks.push(1, 21);
		printStacks(stacks);
		stacks.push(0, 11);
		printStacks(stacks);
		stacks.push(0, 12);
		printStacks(stacks);
		
		stacks.pop(0);
		printStacks(stacks);
		
		stacks.push(2, 31);
		printStacks(stacks);
		
		stacks.push(0, 13);
		printStacks(stacks);
		stacks.push(1, 22);
		printStacks(stacks);
		
		stacks.push(2, 31);
		printStacks(stacks);
		stacks.push(2, 32);
		printStacks(stacks);
		stacks.push(2, 33);
		printStacks(stacks);
		stacks.push(2, 34);
		printStacks(stacks);
		
		stacks.pop(1);
		printStacks(stacks);
		stacks.push(2, 35);
		printStacks(stacks);
		
		System.out.println("Final Stack: " + AssortedMethods.arrayToString(stacks.getValues()));
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_02_Stack_Min/NodeWithMin.java
================================================
package Q3_02_Stack_Min;

class NodeWithMin {
    public int value;
    public int min;
    public NodeWithMin(int v, int min){
        value = v;
        this.min = min;
    }
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_02_Stack_Min/Question.java
================================================
package Q3_02_Stack_Min;

public class Question {
	public static void main(String[] args) {
		StackWithMin stack = new StackWithMin();
		StackWithMin2 stack2 = new StackWithMin2();
		int[] array = {2, 1, 3, 1};
		for (int value : array) {
			stack.push(value);
			stack2.push(value);
			System.out.print(value + ", ");
		}
		System.out.println('\n');
		for (int i = 0; i < array.length; i++) {
			System.out.println("Popped " + stack.pop().value + ", " + stack2.pop());
			System.out.println("New min is " + stack.min() + ", " + stack2.min());
		}
	}

}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_02_Stack_Min/StackWithMin.java
================================================
package Q3_02_Stack_Min;

import java.util.Stack;

public class StackWithMin extends Stack<NodeWithMin> {
    public void push(int value) {
        int newMin = Math.min(value, min());
        super.push(new NodeWithMin(value, newMin));
    }
    
    public int min() {
    	if (this.isEmpty()) {
    		return Integer.MAX_VALUE;
    	} else {
    		return peek().min;
    	}
    }
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_02_Stack_Min/StackWithMin2.java
================================================
package Q3_02_Stack_Min;

import java.util.Stack;

public class StackWithMin2 extends Stack<Integer> {
	Stack<Integer> s2;
	
	public StackWithMin2() {
		s2 = new Stack<Integer>();		
	}
	
	public void push(int value){
		if (value <= min()) {
			s2.push(value);
		}
		super.push(value);
	}
	
	public Integer pop() {
		int value = super.pop();
		if (value == min()) {
			s2.pop();			
		}
		return value;
	}
	
	public int min() {
		if (s2.isEmpty()) {
			return Integer.MAX_VALUE;
		} else {
			return s2.peek();
		}
	}
}




================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_03_Stack_of_Plates/Node.java
================================================
package Q3_03_Stack_of_Plates;

public class Node {
	public Node above;
	public Node below;
	public int value;
	public Node(int value) {
		this.value = value;
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_03_Stack_of_Plates/Question.java
================================================
package Q3_03_Stack_of_Plates;

public class Question {
	public static void main(String[] args) {
		int capacity_per_substack = 5;
		SetOfStacks set = new SetOfStacks(capacity_per_substack);
		for (int i = 0; i < 34; i++) {
			set.push(i);
		}
		for (int i = 0; i < 35; i++) {
			System.out.println("Popped " + set.pop());
		}		
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_03_Stack_of_Plates/SetOfStacks.java
================================================
package Q3_03_Stack_of_Plates;

import java.util.ArrayList;
import java.util.EmptyStackException;

public class SetOfStacks {
	ArrayList<Stack> stacks = new ArrayList<Stack>();
	public int capacity;
	
	public SetOfStacks(int capacity) { 
		this.capacity = capacity; 
	}
	
	public Stack getLastStack() {
		if (stacks.size() == 0) {
			return null;
		}
		return stacks.get(stacks.size() - 1);
	}
	
	public void push(int v) {
		Stack last = getLastStack();
		if (last != null && !last.isFull()) { // add to last
			last.push(v);
		} else { // must create new stack
			Stack stack = new Stack(capacity);
			stack.push(v);
			stacks.add(stack);
		}
	}
	
	public int pop() {
		Stack last = getLastStack();
		if (last == null) throw new EmptyStackException();
		int v = last.pop();
		if (last.size == 0) {
			stacks.remove(stacks.size() - 1);
		}
		return v;
	}
	
	public int popAt(int index) {
		return leftShift(index, true);
	}
	
	public int leftShift(int index, boolean removeTop) {
		Stack stack = stacks.get(index);
		int removed_item;
		if (removeTop) removed_item = stack.pop();
		else removed_item = stack.removeBottom();
		if (stack.isEmpty()) {
			stacks.remove(index);
		} else if (stacks.size() > index + 1) {
			int v = leftShift(index + 1, false);
			stack.push(v);
		}
		return removed_item;
	}
	
	public boolean isEmpty() {
		Stack last = getLastStack();
		return last == null || last.isEmpty();
	}
}



================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_03_Stack_of_Plates/Stack.java
================================================
package Q3_03_Stack_of_Plates;

import java.util.EmptyStackException;

public class Stack {
	private int capacity;
	public Node top;
	public Node bottom;
	public int size = 0;
	
	public Stack(int capacity) { 
		this.capacity = capacity; 
	}
	
	public boolean isFull() { 
		return capacity == size; 
	}
	
	public void join(Node above, Node below) {
		if (below != null) below.above = above;
		if (above != null) above.below = below;
	}
	
	public boolean push(int v) {
		if (size >= capacity) return false;
		size++;
		Node n = new Node(v);
		if (size == 1) bottom = n;
		join(n, top);
		top = n;
		return true;
	}
	
	public int pop() {
		if (top == null) throw new EmptyStackException();
		Node t = top;
		top = top.below;
		size--;
		return t.value;
	}
	
	public boolean isEmpty() { 
		return size == 0; 
	}
	
	public int removeBottom() {
		Node b = bottom;
		bottom = bottom.above;
		if (bottom != null) bottom.below = null;
		size--;
		return b.value;
	}
}



================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_04_Queue_via_Stacks/MyQueue.java
================================================
package Q3_04_Queue_via_Stacks;

import java.util.Stack;

public class MyQueue<T> {
	Stack<T> stackNewest, stackOldest;
	
	public MyQueue() {
		stackNewest = new Stack<T>();
		stackOldest = new Stack<T>();
	}
	
	public int size() {
		return stackNewest.size() + stackOldest.size();
	}
	
	public void add(T value) {
		// Push onto stack1
		stackNewest.push(value);
	}
	
	/* Move elements from stackNewest into stackOldest. This is usually done so that we can
	 * do operations on stackOldest.
	 */
	private void shiftStacks() {
		if (stackOldest.isEmpty()) { 
			while (!stackNewest.isEmpty()) {
				stackOldest.push(stackNewest.pop());
			}
		}
	}
	
	public T peek() {
		shiftStacks();
		return stackOldest.peek(); // retrieve the oldest item.
	}
	
	public T remove() {
		shiftStacks();
		return stackOldest.pop(); // pop the oldest item.
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_04_Queue_via_Stacks/Question.java
================================================
package Q3_04_Queue_via_Stacks;

import java.util.LinkedList;
import java.util.Queue;

import CtCILibrary.AssortedMethods;

public class Question {
	public static void main(String[] args) {
		MyQueue<Integer> my_queue = new MyQueue<Integer>();	
		
		// Let's test our code against a "real" queue
		Queue<Integer> test_queue = new LinkedList<Integer>();
		
		for (int i = 0; i < 100; i++) {
			int choice = AssortedMethods.randomIntInRange(0, 10);
			if (choice <= 5) { // enqueue
				int element = AssortedMethods.randomIntInRange(1, 10);
				test_queue.add(element);
				my_queue.add(element);
				System.out.println("Enqueued " + element);
			} else if (test_queue.size() > 0) {
				int top1 = test_queue.remove();
				int top2 = my_queue.remove();
				if (top1 != top2) { // Check for error
					System.out.println("******* FAILURE - DIFFERENT TOPS: " + top1 + ", " + top2);
				} 
				System.out.println("Dequeued " + top1);
			}
			
			if (test_queue.size() == my_queue.size()) {
				if (test_queue.size() > 0 && test_queue.peek() != my_queue.peek()) {
					System.out.println("******* FAILURE - DIFFERENT TOPS: " + test_queue.peek() + ", " + my_queue.peek() + " ******");
				}
			} else {
				System.out.println("******* FAILURE - DIFFERENT SIZES ******");
			}
		}
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_05_Sort_Stack/Question.java
================================================
package Q3_05_Sort_Stack;

import java.util.Stack;

import CtCILibrary.AssortedMethods;

public class Question {
	public static Stack<Integer> mergesort(Stack<Integer> inStack) {
		if (inStack.size() <= 1) {
			return inStack;
		}

		Stack<Integer> left = new Stack<Integer>();
		Stack<Integer> right = new Stack<Integer>();
		int count = 0;
		while (inStack.size() != 0) {
			count++;
			if (count % 2 == 0) {
				left.push(inStack.pop());
			} else {
				right.push(inStack.pop());
			}
		}

		left = mergesort(left);
		right = mergesort(right);

		while (left.size() > 0 || right.size() > 0) {
			if (left.size() == 0) {
				inStack.push(right.pop());
			} else if (right.size() == 0) {
				inStack.push(left.pop());
			} else if (right.peek().compareTo(left.peek()) <= 0) {
				inStack.push(left.pop());
			} else {
				inStack.push(right.pop());
			}
		}

		Stack<Integer> reverseStack = new Stack<Integer>();
		while (inStack.size() > 0) {
			reverseStack.push(inStack.pop());
		}

		return reverseStack;
	}
	
	public static void sort(Stack<Integer> s) {
		Stack<Integer> r = new Stack<Integer>();
		while(!s.isEmpty()) {
			/* Insert each element in s in sorted order into r. */
			int tmp = s.pop();
			while(!r.isEmpty() && r.peek() > tmp) {
				s.push(r.pop());
			}
			r.push(tmp);
		}
		
		/* Copy the elements back. */
		while (!r.isEmpty()) {
			s.push(r.pop());
		}
	}
		
	public static void main(String [] args) {
		Stack<Integer> s = new Stack<Integer>();
		for (int i = 0; i < 10; i++) {
			int r = AssortedMethods.randomIntInRange(0,  1000);
			s.push(r);
		}
		
		sort(s);
		
		while(!s.isEmpty()) {
			System.out.println(s.pop());
		}
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/Animal.java
================================================
package Q3_06_Animal_Shelter;

public abstract class Animal {
	private int order; 
	protected String name;
	public Animal(String n) {
		name = n;
	}
	
	public abstract String name();
	
	public void setOrder(int ord) {
		order = ord;
	}
	
	public int getOrder() {
		return order;
	}
	
	public boolean isOlderThan(Animal a) {
		return this.order < a.getOrder();
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/AnimalQueue.java
================================================
package Q3_06_Animal_Shelter;

import java.util.LinkedList;

public class AnimalQueue {
	LinkedList<Dog> dogs = new LinkedList<Dog>();
	LinkedList<Cat> cats = new LinkedList<Cat>();
	private int order = 0;
	
	public void enqueue(Animal a) {
		a.setOrder(order);
		order++;
		if (a instanceof Dog) {
			dogs.addLast((Dog) a);
		} else if (a instanceof Cat) {
			cats.addLast((Cat)a);
		}
	}
	
	public Animal dequeueAny() {
		if (dogs.size() == 0) {
			return dequeueCats();
		} else if (cats.size() == 0) {
			return dequeueDogs();
		}
		Dog dog = dogs.peek();
		Cat cat = cats.peek();
		if (dog.isOlderThan(cat)) {
			return dogs.poll();
		} else {
			return cats.poll();
		}
	}
	
	public Animal peek() {
		if (dogs.size() == 0) {
			return cats.peek();
		} else if (cats.size() == 0) {
			return dogs.peek();
		}
		Dog dog = dogs.peek();
		Cat cat = cats.peek();
		if (dog.isOlderThan(cat)) {
			return dog;
		} else {
			return cat;
		}
	}
	
	public int size() {
		return dogs.size() + cats.size();
	}
	
	public Dog dequeueDogs() {
		return dogs.poll();
	}
	
	public Dog peekDogs() {
		return dogs.peek();
	}
	
	public Cat dequeueCats() {
		return cats.poll();
	}
	
	public Cat peekCats() {
		return cats.peek();
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/Cat.java
================================================
package Q3_06_Animal_Shelter;

public class Cat extends Animal {
	public Cat(String n) {
		super(n);
	}
	
	public String name() {
		return "Cat: " + name;
	}
}



================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/Dog.java
================================================
package Q3_06_Animal_Shelter;

public class Dog extends Animal {
	public Dog(String n) {
		super(n);
	}
	
	public String name() {
		return "Dog: " + name;
	}
}


================================================
FILE: Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/Question.java
================================================
package Q3_06_Animal_Shelter;

public class Question {


	public static void main(String[] args) {
		AnimalQueue animals = new AnimalQueue();
		animals.enqueue(new Cat("Callie"));
		animals.enqueue(new Cat("Kiki"));
		animals.enqueue(new Dog("Fido"));
		animals.enqueue(new Dog("Dora"));
		animals.enqueue(new Cat("Kari"));
		animals.enqueue(new Dog("Dexter"));
		animals.enqueue(new Dog("Dobo"));
		animals.enqueue(new Cat("Copa"));
		
		System.out.println(animals.dequeueAny().name());	
		System.out.println(animals.dequeueAny().name());	
		System.out.println(animals.dequeueAny().name());	
		
		animals.enqueue(new Dog("Dapa"));
		animals.enqueue(new Cat("Kilo"));
		
		while (animals.size() != 0) {
			System.out.println(animals.dequeueAny().name());	
		}
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Introduction/Traversals.java
================================================
package Introduction;

import CtCILibrary.TreeNode;

public class Traversals {
	public static void visit(TreeNode node) {
		if (node != null) {
			System.out.println(node.data);
		}
	}
	
	public static void inOrderTraversal(TreeNode node) {
		if (node != null) {
			inOrderTraversal(node.left);
			visit(node);
			inOrderTraversal(node.right);
		}
	}
	
	public static void preOrderTraversal(TreeNode node) {
		if (node != null) {
			visit(node);
			inOrderTraversal(node.left);
			inOrderTraversal(node.right);
		}
	}
	
	public static void postOrderTraversal(TreeNode node) {
		if (node != null) {
			inOrderTraversal(node.left);
			inOrderTraversal(node.right);
			visit(node);
		}
	}	
	
	public static void main(String[] args) {
		int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		
		// We needed this code for other files, so check out the code in the library
		TreeNode root = TreeNode.createMinimalBST(array);
		inOrderTraversal(root);
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_01_Route_Between_Nodes/Graph.java
================================================
package Q4_01_Route_Between_Nodes;

public class Graph {
	public static int MAX_VERTICES = 6;
	private Node vertices[];
	public int count;
	public Graph() {
		vertices = new Node[MAX_VERTICES];
		count = 0;
    }
	
    public void addNode(Node x) {
		if (count < vertices.length) {
			vertices[count] = x;
			count++;
		} else {
			System.out.print("Graph full");
		}
    }
    
    public Node[] getNodes() {
        return vertices;
    }
}



================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_01_Route_Between_Nodes/Node.java
================================================
package Q4_01_Route_Between_Nodes;

class Node {
    private Node adjacent[];
    public int adjacentCount;
    private String vertex;
    public Question.State state;
    public Node(String vertex, int adjacentLength) {
        this.vertex = vertex;                
        adjacentCount = 0;        
        adjacent = new Node[adjacentLength];
    }
    
    public void addAdjacent(Node x) {
        if (adjacentCount < adjacent.length) {
            this.adjacent[adjacentCount] = x;
            adjacentCount++;
        } else {
            System.out.print("No more adjacent can be added");
        }
    }
    public Node[] getAdjacent() {
        return adjacent;
    }
    public String getVertex() {
        return vertex;
    }
}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_01_Route_Between_Nodes/Question.java
================================================
package Q4_01_Route_Between_Nodes;

import java.util.LinkedList;

public class Question {
	public enum State {
		Unvisited, Visited, Visiting;
	} 

	public static void main(String a[])
	{
		Graph g = createNewGraph();
		Node[] n = g.getNodes();
		Node start = n[3];
		Node end = n[5];
		System.out.println(search(g, start, end));
	}
	
	public static Graph createNewGraph()
	{
		Graph g = new Graph();        
		Node[] temp = new Node[6];

		temp[0] = new Node("a", 3);
		temp[1] = new Node("b", 0);
		temp[2] = new Node("c", 0);
		temp[3] = new Node("d", 1);
		temp[4] = new Node("e", 1);
		temp[5] = new Node("f", 0);

		temp[0].addAdjacent(temp[1]);
		temp[0].addAdjacent(temp[2]);
		temp[0].addAdjacent(temp[3]);
		temp[3].addAdjacent(temp[4]);
		temp[4].addAdjacent(temp[5]);
		for (int i = 0; i < 6; i++) {
			g.addNode(temp[i]);
		}
		return g;
	}

    public static boolean search(Graph g,Node start,Node end) {  
        LinkedList<Node> q = new LinkedList<Node>();
        for (Node u : g.getNodes()) {
            u.state = State.Unvisited;
        }
        start.state = State.Visiting;
        q.add(start);
        Node u;
        while(!q.isEmpty()) {
            u = q.removeFirst();
            if (u != null) {
	            for (Node v : u.getAdjacent()) {
	                if (v.state == State.Unvisited) {
	                    if (v == end) {
	                        return true;
	                    } else {
	                        v.state = State.Visiting;
	                        q.add(v);
	                    }
	                }
	            }
	            u.state = State.Visited;
            }
        }
        return false;
    }
}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_02_Minimal_Tree/Question.java
================================================
package Q4_02_Minimal_Tree;

import CtCILibrary.TreeNode;

public class Question {	
	public static void main(String[] args) {
		int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		
		// We needed this code for other files, so check out the code in the library
		TreeNode root = TreeNode.createMinimalBST(array);
		System.out.println("Root? " + root.data);
		System.out.println("Created BST? " + root.isBST());
		System.out.println("Height: " + root.height());
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_03_List_of_Depths/QuestionBFS.java
================================================
package Q4_03_List_of_Depths;

import CtCILibrary.*;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

public class QuestionBFS {

	public static ArrayList<LinkedList<TreeNode>> createLevelLinkedList(TreeNode root) {
		ArrayList<LinkedList<TreeNode>> result = new ArrayList<LinkedList<TreeNode>>();
		
		/* "Visit" the root */
		LinkedList<TreeNode> current = new LinkedList<TreeNode>();
		if (root != null) {
			current.add(root);
		}
		
		while (current.size() > 0) {
			result.add(current); // Add previous level
			LinkedList<TreeNode> parents = current; // Go to next level
			current = new LinkedList<TreeNode>(); 
			for (TreeNode parent : parents) {
				/* Visit the children */
				if (parent.left != null) {
					current.add(parent.left);
				}
				if (parent.right != null) {
					current.add(parent.right);
				}
			}
		}

		return result;
	}
	
	public static void printResult(ArrayList<LinkedList<TreeNode>> result){
		int depth = 0;
		for(LinkedList<TreeNode> entry : result) {
			Iterator<TreeNode> i = entry.listIterator();
			System.out.print("Link list at depth " + depth + ":");
			while(i.hasNext()){
				System.out.print(" " + ((TreeNode)i.next()).data);
			}
			System.out.println();
			depth++;
		}
	}
	

	public static void main(String[] args) {
		int[] nodes_flattened = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		TreeNode root = AssortedMethods.createTreeFromArray(nodes_flattened);
		ArrayList<LinkedList<TreeNode>> list = createLevelLinkedList(root);
		printResult(list);
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_03_List_of_Depths/QuestionDFS.java
================================================
package Q4_03_List_of_Depths;

import CtCILibrary.*;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

public class QuestionDFS {

	public static void createLevelLinkedList(TreeNode root, ArrayList<LinkedList<TreeNode>> lists, int level) {
		if (root == null) return;
		LinkedList<TreeNode> list = null;
		if (lists.size() == level) { // Level not contained in list
			list = new LinkedList<TreeNode>();
			/* Levels are always traversed in order. So, if this is the first time we've visited level i,
			 * we must have seen levels 0 through i - 1. We can therefore safely add the level at the end. */
			lists.add(list);  
		} else {
			list = lists.get(level);
		}
		list.add(root);
		createLevelLinkedList(root.left, lists, level + 1);
		createLevelLinkedList(root.right, lists, level + 1);
	}
	
	public static ArrayList<LinkedList<TreeNode>> createLevelLinkedList(TreeNode root) {
		ArrayList<LinkedList<TreeNode>> lists = new ArrayList<LinkedList<TreeNode>>();
		createLevelLinkedList(root, lists, 0);
		return lists;
	}	
	
	public static void printResult(ArrayList<LinkedList<TreeNode>> result){
		int depth = 0;
		for(LinkedList<TreeNode> entry : result) {
			Iterator<TreeNode> i = entry.listIterator();
			System.out.print("Link list at depth " + depth + ":");
			while(i.hasNext()){
				System.out.print(" " + ((TreeNode)i.next()).data);
			}
			System.out.println();
			depth++;
		}
	}
	

	public static void main(String[] args) {
		int[] nodes_flattened = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		TreeNode root = AssortedMethods.createTreeFromArray(nodes_flattened);
		ArrayList<LinkedList<TreeNode>> list = createLevelLinkedList(root);
		printResult(list);
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_04_Check_Balanced/QuestionBrute.java
================================================
package Q4_04_Check_Balanced;

import CtCILibrary.AssortedMethods;
import CtCILibrary.TreeNode;

public class QuestionBrute {
	
	public static int getHeight(TreeNode root) {
		if (root == null) {
			return -1;
		}
		return Math.max(getHeight(root.left), getHeight(root.right)) + 1;
	}
		
	public static boolean isBalanced(TreeNode root) {
		if (root == null) {
			return true;
		}
		int heightDiff = getHeight(root.left) - getHeight(root.right);
		if (Math.abs(heightDiff) > 1) {
			return false;
		}
		else {
			return isBalanced(root.left) && isBalanced(root.right);
		}
	}
	
	public static void main(String[] args) {
		// Create balanced tree
		int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		TreeNode root = TreeNode.createMinimalBST(array);
		System.out.println("Root? " + root.data);
		System.out.println("Is balanced? " + isBalanced(root));
		
		// Could be balanced, actually, but it's very unlikely...
		TreeNode unbalanced = new TreeNode(10);
		for (int i = 0; i < 10; i++) {
			unbalanced.insertInOrder(AssortedMethods.randomIntInRange(0, 100));
		}
		System.out.println("Root? " + unbalanced.data);
		System.out.println("Is balanced? " + isBalanced(unbalanced));
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_04_Check_Balanced/QuestionImproved.java
================================================
package Q4_04_Check_Balanced;
import CtCILibrary.TreeNode;

public class QuestionImproved {
		
	public static int checkHeight(TreeNode root) {
		if (root == null) {
			return -1;
		}
		int leftHeight = checkHeight(root.left);
		if (leftHeight == Integer.MIN_VALUE) return Integer.MIN_VALUE; // Propagate error up
		
		int rightHeight = checkHeight(root.right);
		if (rightHeight == Integer.MIN_VALUE) return Integer.MIN_VALUE; // Propagate error up
		
		int heightDiff = leftHeight - rightHeight;
		if (Math.abs(heightDiff) > 1) {
			return Integer.MIN_VALUE; // Found error -> pass it back
		} else {
			return Math.max(leftHeight, rightHeight) + 1;
		}
	}
	
	public static boolean isBalanced(TreeNode root) {
		return checkHeight(root) != Integer.MIN_VALUE;
	}
	
	public static void main(String[] args) {
		// Create balanced tree
		int[] array = {0, 1, 2, 3, 5, 6, 7, 8, 9, 10};
		TreeNode root = TreeNode.createMinimalBST(array);

		
		System.out.println("Is balanced? " + isBalanced(root));
		
		root.insertInOrder(4); // Add 4 to make it unbalanced

		System.out.println("Is balanced? " + isBalanced(root));
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_05_Validate_BST/IntWrapper.java
================================================
package Q4_05_Validate_BST;

public class IntWrapper {
	public IntWrapper(int m) {
		data = m;
	}
	public int data;
}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_05_Validate_BST/Question.java
================================================
package Q4_05_Validate_BST;

import CtCILibrary.TreeNode;

public class Question {
	public static Integer lastPrinted = null;

	public static boolean checkBST(TreeNode node) {
		return checkBST(node, true);
	}

	// Allow "equal" value only for left child. This validates the BST property.
	public static boolean checkBST(TreeNode n, boolean isLeft) {
		if (n == null) {
			return true;
		}
		
		// Check / recurse left
		if (!checkBST(n.left, true)) {
			return false;
		}
		
		// Check current
		if (lastPrinted != null) {
			if (isLeft) {
				// left child "is allowed" be equal to parent.
				if (n.data < lastPrinted) {
					return false;
				}
			} else {
				// Right child "is not allowed" be equal to parent.
				if (n.data <= lastPrinted) {
					return false;
				}
			}
		}
		lastPrinted = n.data;
		
		// Check / recurse right
		if (!checkBST(n.right, false)) {
			return false;
		}
		return true;
	}

	public static void main(String[] args) {
		int[] array = {Integer.MIN_VALUE, Integer.MAX_VALUE - 2, Integer.MAX_VALUE - 1, Integer.MAX_VALUE};
		TreeNode node = TreeNode.createMinimalBST(array);
		//node.left.data = 5;
		//node.left.right.data = 3;
		System.out.println(checkBST(node));

		test();
	}

	public static void test() {
		TreeNode node;
		boolean condition;
		System.out.println("test cases for equals condition.");

		/* Expect true: for left child: node.data <= last_printed.
   2
  / \
 /   \
 2   3
      \
      4
		*/
		int[] array2 = {1, 2, 3, 4};
		node = TreeNode.createMinimalBST(array2);
		node.left.data = 2;
		node.print();
		lastPrinted = null;
		condition = checkBST(node);
		System.out.println("should be true: " + condition);

		/* Expect false: for right child: node.data <= last_printed.
   2
  / \
 /   \
 1   2
      \
      4
		 */
		int[] array3 = {1, 2, 3, 4};
		node = TreeNode.createMinimalBST(array3);
		node.right.data = 2;
		node.print();
		lastPrinted = null;
		condition = checkBST(node);
		System.out.println("should be false: " + condition);
	}
}

================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_05_Validate_BST/QuestionB.java
================================================
package Q4_05_Validate_BST;

import CtCILibrary.AssortedMethods;
import CtCILibrary.TreeNode;

public class QuestionB {
	public static boolean checkBST(TreeNode n, Integer min, Integer max) {
		if (n == null) {
			return true;
		}
		if ((min != null && n.data <= min) || (max != null && n.data > max)) {
			return false;
		}
		if (!checkBST(n.left, min, n.data) ||
			!checkBST(n.right, n.data, max)) {
			return false;
		}
		return true;
	}
		
	public static boolean checkBST(TreeNode n) {
		return checkBST(n, null, null);
	}
	
	public static boolean checkBSTAlternate(TreeNode n) {
		return checkBSTAlternate(n, new IntWrapper(0), new IntWrapper(0));
	}		

	public static boolean checkBSTAlternate(TreeNode n, IntWrapper min, IntWrapper max) {
		/* An alternate, less clean approach. This is not provided in the book, but is used to test the other method. */
		if (n.left == null) {
			min.data = n.data;
		} else {
			IntWrapper leftMin = new IntWrapper(0);
			IntWrapper leftMax = new IntWrapper(0);
			if (!checkBSTAlternate(n.left, leftMin, leftMax)) {
				return false;
			}
			if (leftMax.data > n.data) {
				return false;
			}
			min.data = leftMin.data;
		}
		if (n.right == null) {
			max.data = n.data;
		} else {
			IntWrapper rightMin = new IntWrapper(0);
			IntWrapper rightMax = new IntWrapper(0);
			if (!checkBSTAlternate(n.right, rightMin, rightMax)) {
				return false;
			}
			if (rightMin.data <= n.data) {
				return false;
			}
			max.data = rightMax.data;
		}
		return true;
	}

	/* Create a tree that may or may not be a BST */
	public static TreeNode createTestTree() {
		/* Create a random BST */
		TreeNode head = AssortedMethods.randomBST(10, -10, 10); 
		
		/* Insert an element into the BST and potentially ruin the BST property */
		TreeNode node = head;
		do {
			int n = AssortedMethods.randomIntInRange(-10, 10);
			int rand = AssortedMethods.randomIntInRange(0, 5);
			if (rand == 0) {
				node.data = n;
			} else if (rand == 1) {
				node = node.left;
			} else if (rand == 2) {
				node = node.right;
			} else if (rand == 3 || rand == 4) {
				break;
			}
		} while (node != null);	
		
		return head;
	}
	
	public static void main(String[] args) {
		/* Simple test -- create one */
		int[] array = {Integer.MIN_VALUE, 3, 5, 6, 10, 13, 15, Integer.MAX_VALUE};
		TreeNode node = TreeNode.createMinimalBST(array);
		//node.left.data = 6; // "ruin" the BST property by changing one of the elements
		node.print();
		boolean isBst = checkBST(node);
		System.out.println(isBst);
		
		/* More elaborate test -- creates 100 trees (some BST, some not) and compares the outputs of various methods. */
		/*for (int i = 0; i < 100; i++) {
			TreeNode head = createTestTree();
			
			// Compare results 
			boolean isBst1 = checkBST(head);
			boolean isBst2 = checkBSTAlternate(head);
			
			if (isBst1 != isBst2) {
				System.out.println("*********************** ERROR *******************");
				head.print();
				break;
			} else {
				System.out.println(isBst1 + " | " + isBst2);
				head.print();
			}
		}*/
	}
}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_06_Successor/Question.java
================================================
package Q4_06_Successor;

import CtCILibrary.TreeNode;

public class Question {

	public static TreeNode inorderSucc(TreeNode n) { 
		if (n == null) return null;
		
		// Found right children -> return left most node of right subtree
		if (n.parent == null || n.right != null) { 
			return leftMostChild(n.right); 
		} else { 
			TreeNode q = n;
			TreeNode x = q.parent;
			// Go up until we're on left instead of right
			while (x != null && x.left != q) {
				q = x;
				x = x.parent;
			}
			return x;
		}  
	} 
		
	public static TreeNode leftMostChild(TreeNode n) {
		if (n == null) {
			return null;
		}
		while (n.left != null) {
			n = n.left; 
		}
		return n; 
	}
	
	public static void main(String[] args) {
		int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		TreeNode root = TreeNode.createMinimalBST(array);
		for (int i = 0; i < array.length; i++) {
			TreeNode node = root.find(array[i]);
			TreeNode next = inorderSucc(node);
			if (next != null) {
				System.out.println(node.data + "->" + next.data);
			} else {
				System.out.println(node.data + "->" + null);
			}
		}
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/DFS/Graph.java
================================================
package Q4_07_Build_Order.DFS;

import java.util.ArrayList;
import java.util.HashMap;

public class Graph {
	private ArrayList<Project> nodes = new ArrayList<Project>();
	private HashMap<String, Project> map = new HashMap<String, Project>();
	
	public Project getOrCreateNode(String name) {
		if (!map.containsKey(name)) {
			Project node = new Project(name);
			nodes.add(node);
			map.put(name, node);
		}
		
		return map.get(name);
	}
	
	public void addEdge(String startName, String endName) {
		Project start = getOrCreateNode(startName);
		Project end = getOrCreateNode(endName);
		start.addNeighbor(end);
	}
	
	public ArrayList<Project> getNodes() {
		return nodes;
	}
}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/DFS/Project.java
================================================
package Q4_07_Build_Order.DFS;

import java.util.ArrayList;
import java.util.HashMap;

public class Project {
	public enum State {COMPLETE, PARTIAL, BLANK};
	private ArrayList<Project> children = new ArrayList<Project>();
	private HashMap<String, Project> map = new HashMap<String, Project>();
	private String name;
	private State state = State.BLANK;
	
	public Project(String n) {
		name = n;
	}

	public String getName() {
		return name;
	}
	
	public void addNeighbor(Project node) {
		if (!map.containsKey(node.getName())) {
			children.add(node);
			map.put(node.getName(), node);
		}
	}
	
	public State getState() { 
		return state;
	}
	
	public void setState(State st) {
		state = st;
	}
	
	public ArrayList<Project> getChildren() {
		return children;
	}
}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/DFS/Question.java
================================================
package Q4_07_Build_Order.DFS;

import java.util.ArrayList;
import java.util.Stack;

public class Question {

	/* Build the graph, adding the edge (a, b) if b is dependent on a. 
	 * Assumes a pair is listed in “build order” (which is the reverse 
	 * of dependency order). The pair (a, b) in dependencies indicates
	 * that b depends on a and a must be built before a. */
	public static Graph buildGraph(String[] projects, String[][] dependencies) {
		Graph graph = new Graph();
		
		for (String[] dependency : dependencies) {
			String first = dependency[0];
			String second = dependency[1];
			graph.addEdge(first, second);
		}
		
		return graph;
	}
	
	public static boolean doDFS(Project project, Stack<Project> stack) {
		if (project.getState() == Project.State.PARTIAL) {
			return false; // Cycle
		}
		
		if (project.getState() == Project.State.BLANK) {
			project.setState(Project.State.PARTIAL);
			ArrayList<Project> children = project.getChildren();
			for (Project child : children) {
				if (!doDFS(child, stack)) {
					return false;
				}
			}
			project.setState(Project.State.COMPLETE);
			stack.push(project);
		}
		return true;
	}
	
	public static Stack<Project> orderProjects(ArrayList<Project> projects) {
		Stack<Project> stack = new Stack<Project>();
		for (Project project : projects) {
			if (project.getState() == Project.State.BLANK) {
				if (!doDFS(project, stack)) {
					return null;
				}
			}
		}
		return stack;
	}
	
	public static String[] convertToStringList(Stack<Project> projects) {
		String[] buildOrder = new String[projects.size()];
		for (int i = 0; i < buildOrder.length; i++) {
			buildOrder[i] = projects.pop().getName();
		}
		return buildOrder;
	}
	
	public static Stack<Project> findBuildOrder(String[] projects, String[][] dependencies) {
		Graph graph = buildGraph(projects, dependencies);
		return orderProjects(graph.getNodes());
	}
	
	public static String[] buildOrderWrapper(String[] projects, String[][] dependencies) {
		Stack<Project> buildOrder = findBuildOrder(projects, dependencies);
		if (buildOrder == null) return null;
		String[] buildOrderString = convertToStringList(buildOrder);
		return buildOrderString;
	}
	
	public static void main(String[] args) {
		String[] projects = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};
		String[][] dependencies = {
				{"a", "b"},
				{"b", "c"},
				{"a", "c"},
				{"d", "e"},
				{"b", "d"},
				{"e", "f"},
				{"a", "f"},
				{"h", "i"},
				{"h", "j"},
				{"i", "j"},
				{"g", "j"}};
		String[] buildOrder = buildOrderWrapper(projects, dependencies);
		if (buildOrder == null) {
			System.out.println("Circular Dependency.");
		} else {
			for (String s : buildOrder) {
				System.out.println(s);
			}
		}
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/EdgeRemoval/Graph.java
================================================
package Q4_07_Build_Order.EdgeRemoval;

import java.util.ArrayList;
import java.util.HashMap;

public class Graph {
	private ArrayList<Project> nodes = new ArrayList<Project>();
	private HashMap<String, Project> map = new HashMap<String, Project>();
	
	public Project getOrCreateNode(String name) {
		if (!map.containsKey(name)) {
			Project node = new Project(name);
			nodes.add(node);
			map.put(name, node);
		}
		
		return map.get(name);
	}
	
	public void addEdge(String startName, String endName) {
		Project start = getOrCreateNode(startName);
		Project end = getOrCreateNode(endName);
		start.addNeighbor(end);
	}
	
	public ArrayList<Project> getNodes() {
		return nodes;
	}
}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/EdgeRemoval/Project.java
================================================
package Q4_07_Build_Order.EdgeRemoval;

import java.util.ArrayList;
import java.util.HashMap;

public class Project {
	private ArrayList<Project> children = new ArrayList<Project>();
	private HashMap<String, Project> map = new HashMap<String, Project>();
	private String name;
	private int dependencies = 0;
	
	public Project(String n) {
		name = n;
	}

	public String getName() {
		return name;
	}
	
	public void addNeighbor(Project node) {
		if (!map.containsKey(node.getName())) {
			children.add(node);
			map.put(node.getName(), node);
			node.incrementDependencies();
		}
	}
	
	public void incrementDependencies() {
		dependencies++;
	}
	
	public ArrayList<Project> getChildren() {
		return children;
	}
	
	public void decrementDependencies() {
		dependencies--;
	}
	
	public int getNumberDependencies() {
		return dependencies;
	}
}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/EdgeRemoval/Question.java
================================================
package Q4_07_Build_Order.EdgeRemoval;

import java.util.ArrayList;

public class Question {

	/* Build the graph, adding the edge (a, b) if b is dependent on a. 
	 * Assumes a pair is listed in “build order”. The pair (a, b) in 
	 * dependencies indicates that b depends on a and a must be built
	 * before b. */
	public static Graph buildGraph(String[] projects, String[][] dependencies) {
		Graph graph = new Graph();
		for (String project : projects) {
			graph.getOrCreateNode(project);
		}
		
		for (String[] dependency : dependencies) {
			String first = dependency[0];
			String second = dependency[1];
			graph.addEdge(first, second);
		}
		
		return graph;
	}
	
	/* A helper function to insert projects with zero dependencies 
	 * into the order array, starting at index offset. */
	public static int addNonDependent(Project[] order, ArrayList<Project> projects, int offset) {
		for (Project project : projects) {
			if (project.getNumberDependencies() == 0) {
				order[offset] = project;
				offset++;
			}
		}
		return offset;
	}
	
	public static Project[] orderProjects(ArrayList<Project> projects) {
		Project[] order = new Project[projects.size()];
		
		/* Add “roots” to the build order first.*/
		int endOfList = addNonDependent(order, projects, 0);
		
		int toBeProcessed = 0;
		while (toBeProcessed < order.length) {
			Project current = order[toBeProcessed];
			
			/* We have a circular dependency since there are no remaining
			 * projects with zero dependencies. */ 
			if (current == null) {
				return null;
			}
			
			/* Remove myself as a dependency. */
			ArrayList<Project> children = current.getChildren();
			for (Project child : children) {
				child.decrementDependencies();
			}			
			
			/* Add children that have no one depending on them. */
			endOfList = addNonDependent(order, children, endOfList);
			
			toBeProcessed++;
		}
		
		return order;
	}
	
	public static String[] convertToStringList(Project[] projects) {
		String[] buildOrder = new String[projects.length];
		for (int i = 0; i < projects.length; i++) {
			buildOrder[i] = projects[i].getName();
		}
		return buildOrder;
	}
	
	public static Project[] findBuildOrder(String[] projects, String[][] dependencies) {
		Graph graph = buildGraph(projects, dependencies);
		return orderProjects(graph.getNodes());
	}
	
	
	public static String[] buildOrderWrapper(String[] projects, String[][] dependencies) {
		Project[] buildOrder = findBuildOrder(projects, dependencies);
		if (buildOrder == null) return null;
		String[] buildOrderString = convertToStringList(buildOrder);
		return buildOrderString;
	}
	
	public static void main(String[] args) {
		String[] projects = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};
		String[][] dependencies = {
				{"a", "b"},
				{"b", "c"},
				{"a", "c"},
				{"a", "c"},
				{"d", "e"},
				{"b", "d"},
				{"e", "f"},
				{"a", "f"},
				{"h", "i"},
				{"h", "j"},
				{"i", "j"},
				{"g", "j"}};
		String[] buildOrder = buildOrderWrapper(projects, dependencies);
		if (buildOrder == null) {
			System.out.println("Circular Dependency.");
		} else {
			for (String s : buildOrder) {
				System.out.println(s);
			}
		}
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/Question.java
================================================
package Q4_08_First_Common_Ancestor;

import CtCILibrary.TreeNode;

public class Question {
	static int TWO_NODES_FOUND = 2;
	static int ONE_NODE_FOUND = 1;
	static int NO_NODES_FOUND = 0;
		
	// Checks how many 'special' nodes are located under this root
	public static int covers(TreeNode root, TreeNode p, TreeNode q) {
		int ret = NO_NODES_FOUND;
		if (root == null) return ret;
		if (root == p || root == q) ret += 1;
		ret += covers(root.left, p, q);
		if(ret == TWO_NODES_FOUND) // Found p and q 
			return ret;
		return ret + covers(root.right, p, q);
	}
		
	public static TreeNode commonAncestor(TreeNode root, TreeNode p, TreeNode q) {
		if (q == p && (root.left == q || root.right == q)) return root;
		int nodesFromLeft = covers(root.left, p, q); // Check left side
		if (nodesFromLeft == TWO_NODES_FOUND) {
			if(root.left == p || root.left == q) return root.left;
			else return commonAncestor(root.left, p, q);
		} else if (nodesFromLeft == ONE_NODE_FOUND) {
			if (root == p) return p;
			else if (root == q) return q;
		}

		int nodesFromRight = covers(root.right, p, q); // Check right side
		if(nodesFromRight == TWO_NODES_FOUND) {
			if(root.right == p || root.right == q) return root.right;
			else return commonAncestor(root.right, p, q);
		} else if (nodesFromRight == ONE_NODE_FOUND) {
			if (root == p) return p;
			else if (root == q) return q;
		}
		if (nodesFromLeft == ONE_NODE_FOUND && 
			nodesFromRight == ONE_NODE_FOUND) return root;
		else return null;
	}
	
	public static void main(String[] args) {
		int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		TreeNode root = TreeNode.createMinimalBST(array);
		TreeNode n3 = root.find(1);
		TreeNode n7 = root.find(7);
		TreeNode ancestor = commonAncestor(root, n3, n7);
		System.out.println(ancestor.data);
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionA.java
================================================
package Q4_08_First_Common_Ancestor;

import CtCILibrary.TreeNode;

public class QuestionA {
	public static TreeNode commonAncestor(TreeNode p, TreeNode q) {
		if (p == q) return p;
		
		TreeNode ancestor = p;
		while (ancestor != null) {
			if (isOnPath(ancestor, q)) {
				return ancestor;
			}
			ancestor = ancestor.parent;
		}
		return null;
	}
	
	public static boolean isOnPath(TreeNode ancestor, TreeNode node) {
		while (node != ancestor && node != null) {
			node = node.parent;
		}
		return node == ancestor;
	}	
	
	public static void main(String[] args) {
		int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		TreeNode root = TreeNode.createMinimalBST(array);
		TreeNode n3 = root.find(8);
		TreeNode n7 = root.find(8);
		TreeNode ancestor = commonAncestor(n3, n7);
		System.out.println(ancestor.data);
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionB.java
================================================
package Q4_08_First_Common_Ancestor;

import CtCILibrary.TreeNode;

public class QuestionB {
	public static TreeNode commonAncestor(TreeNode p, TreeNode q) {
		int delta = depth(p) - depth(q); // get difference in depths
		TreeNode first = delta > 0 ? q : p; // get shallower node
		TreeNode second = delta > 0 ? p : q; // get deeper node
		second = goUpBy(second, Math.abs(delta)); // move shallower node to depth of deeper
		while (first != second && first != null && second != null) {
			first = first.parent;
			second = second.parent;
		}
		return first == null || second == null ? null : first;
	}
	
	public static TreeNode goUpBy(TreeNode node, int delta) {
		while (delta > 0 && node != null) {
			node = node.parent;
			delta--;
		}
		return node;
	}
	
	public static int depth(TreeNode node) {
		int depth = 0;
		while (node != null) {
			node = node.parent;
			depth++;
		}
		return depth;
	}	
	
	public static void main(String[] args) {
		int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		TreeNode root = TreeNode.createMinimalBST(array);
		TreeNode n3 = root.find(3);
		TreeNode n7 = root.find(7);
		TreeNode ancestor = commonAncestor(n3, n7);
		System.out.println(ancestor.data);
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionC.java
================================================
package Q4_08_First_Common_Ancestor;

import CtCILibrary.TreeNode;

public class QuestionC {
	
	public static TreeNode commonAncestor(TreeNode root, TreeNode p, TreeNode q) {
		if (!covers(root, p) || !covers(root, q)) {
			return null;
		} else if (covers(p, q)) {
			return p;
		} else if (covers(q, p)) {
			return q;
		}
		
		TreeNode sibling = getSibling(p);
		TreeNode parent = p.parent;
		while (!covers(sibling, q)) {
			sibling = getSibling(parent);
			parent = parent.parent;
		}
		return parent;
	}
	
	public static boolean covers(TreeNode root, TreeNode p) { 
		if (root == null) return false;
		if (root == p) return true;
		return covers(root.left, p) || covers(root.right, p); 
	}
	
	public static TreeNode getSibling(TreeNode node) {
		if (node == null || node.parent == null) {
			return null;
		}
		
		TreeNode parent = node.parent;
		return parent.left == node ? parent.right : parent.left;
	}
	
	public static void main(String[] args) {
		int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		TreeNode root = TreeNode.createMinimalBST(array);
		TreeNode n3 = root.find(1);
		TreeNode n7 = root.find(7);
		TreeNode ancestor = commonAncestor(root, n3, n7);
		System.out.println(ancestor.data);
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionD.java
================================================
package Q4_08_First_Common_Ancestor;

import CtCILibrary.TreeNode;

public class QuestionD {
	
	public static TreeNode commonAncestor(TreeNode root, TreeNode p, TreeNode q) {
		if (!covers(root, p) || !covers(root, q)) { // Error check - one node is not in tree
			return null;
		}
		return ancestorHelper(root, p, q);
	}
	
	public static TreeNode ancestorHelper(TreeNode root, TreeNode p, TreeNode q) {
		if (root == null || root == p || root == q) {
			return root;
		}
		
		boolean pIsOnLeft = covers(root.left, p);
		boolean qIsOnLeft = covers(root.left, q);
		if (pIsOnLeft != qIsOnLeft) { // Nodes are on different side
			return root;
		}
		TreeNode childSide = pIsOnLeft ? root.left : root.right;
		return ancestorHelper(childSide, p, q);
	}	
	
	public static boolean covers(TreeNode root, TreeNode p) { 
		if (root == null) return false;
		if (root == p) return true;
		return covers(root.left, p) || covers(root.right, p); 
	}
		
	
	
	public static void main(String[] args) {
		int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		TreeNode root = TreeNode.createMinimalBST(array);
		TreeNode n3 = root.find(1);
		TreeNode n7 = root.find(7);
		TreeNode ancestor = commonAncestor(root, n3, n7);
		System.out.println(ancestor.data);
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionE.java
================================================
package Q4_08_First_Common_Ancestor;

import CtCILibrary.TreeNode;

public class QuestionE {
	public static class Result {
		public TreeNode node;
		public boolean isAncestor;
		public Result(TreeNode n, boolean isAnc) {
			node = n;
			isAncestor = isAnc;
		}
	}
	
	public static Result commonAncestorHelper(TreeNode root, TreeNode p, TreeNode q) {
		if (root == null) {
			return new Result(null, false);
		}
		if (root == p && root == q) {
			return new Result(root, true);
		}
		
		Result rx = commonAncestorHelper(root.left, p, q);
		if (rx.isAncestor) { // Found common ancestor
			return rx;
		}
		
		Result ry = commonAncestorHelper(root.right, p, q);
		if (ry.isAncestor) { // Found common ancestor
			return ry;
		}
		
		if (rx.node != null && ry.node != null) {
			return new Result(root, true); // This is the common ancestor
		} else if (root == p || root == q) {
			/* If we�re currently at p or q, and we also found one of those
			 * nodes in a subtree, then this is truly an ancestor and the
			 * flag should be true. */
			boolean isAncestor = rx.node != null || ry.node != null;
			return new Result(root, isAncestor);
		} else {
			return new Result(rx.node != null ? rx.node : ry.node, false);
		}
	}	
	
	public static TreeNode commonAncestor(TreeNode root, TreeNode p, TreeNode q) {
		Result r = commonAncestorHelper(root, p, q);
		if (r.isAncestor) {
			return r.node;
		}
		return null;
	}	
	
	public static void main(String[] args) {
		int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		TreeNode root = TreeNode.createMinimalBST(array);
		TreeNode n3 = root.find(10);
		TreeNode n7 = root.find(6);
		TreeNode ancestor = commonAncestor(root, n3, n7);
		if (ancestor != null) {
			System.out.println(ancestor.data);
		} else {
			System.out.println("null");
		}
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionEBad.java
================================================
package Q4_08_First_Common_Ancestor;

import CtCILibrary.TreeNode;

public class QuestionEBad {
	public static TreeNode commonAncestorBad(TreeNode root, TreeNode p, TreeNode q) {
		if (root == null) {
			return null;
		}
		if (root == p && root == q) {
			return root;
		}
		
		TreeNode x = commonAncestorBad(root.left, p, q);
		if (x != null && x != p && x != q) { // Found common ancestor
			return x;
		}
		
		TreeNode y = commonAncestorBad(root.right, p, q);
		if (y != null && y != p && y != q) {
			return y;
		}
		
		if (x != null && y != null) {
			return root; // This is the common ancestor
		} else if (root == p || root == q) {
			return root;
		} else {
			return x == null ? y : x;
		}
	}	
	
	public static void main(String[] args) {
		int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		TreeNode root = TreeNode.createMinimalBST(array);
		TreeNode n3 = root.find(9);
		TreeNode n7 = new TreeNode(6);//root.find(10);
		TreeNode ancestor = commonAncestorBad(root, n3, n7);
		if (ancestor != null) {
			System.out.println(ancestor.data);
		} else {
			System.out.println("null");
		}
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionF.java
================================================
package Q4_08_First_Common_Ancestor;

import CtCILibrary.TreeNode;

public class QuestionF {
	
	public static TreeNode commonAncestor(TreeNode root, TreeNode p, TreeNode q) {
		if ((p == null) || (q == null)) {
			return null;
		}
		
		TreeNode ap = p.parent;
		while (ap != null) {
			TreeNode aq = q.parent;
			while (aq != null) { 
				if (aq == ap) {
					return aq;
				}
				aq = aq.parent;
			}
			ap = ap.parent;
		}
		return null;
	}
	
	public static void main(String[] args) {
		int[] array = {5, 3, 6, 1, 9, 11};
		TreeNode root = new TreeNode(20);
		for (int a : array) {
			root.insertInOrder(a);
		}
		TreeNode n1 = root.find(1);
		TreeNode n9 = root.find(9);
		TreeNode ancestor = commonAncestor(root, n1, n9);
		System.out.println(ancestor.data);
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/Tester.java
================================================
package Q4_08_First_Common_Ancestor;

import java.util.ArrayList;

import CtCILibrary.TreeNode;

public class Tester {
	public static String resultToString(String s, TreeNode x, TreeNode y, TreeNode anc) {
		s += ": ";
		s += (x == null ? "null" : x.data);
		s += " & ";
		s += (y == null ? "null" : y.data);
		s += " -> ";
		s += (anc == null ? "null" : anc.data);
		return s;
	}
	
	public static void main(String[] args) {
		int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		TreeNode root = TreeNode.createMinimalBST(array);
		
		ArrayList<TreeNode> nodes = new ArrayList<TreeNode>();
		for (int a : array) {
			nodes.add(root.find(a));
		}
		nodes.add(new TreeNode(11));
		
		for (TreeNode x : nodes) {
			for (TreeNode y : nodes) {
				TreeNode r1 = QuestionA.commonAncestor(x, y);
				TreeNode r2 = QuestionB.commonAncestor(x, y);
				TreeNode r3 = QuestionC.commonAncestor(root, x, y);
				TreeNode r4 = QuestionD.commonAncestor(root, x, y);
				TreeNode r5 = QuestionE.commonAncestor(root, x, y);
				
				String s1 = resultToString("A", x, y, r1);
				String s2 = resultToString("B", x, y, r2);
				String s3 = resultToString("C", x, y, r3);
				String s4 = resultToString("D", x, y, r4);
				String s5 = resultToString("D", x, y, r5);
				
				if (r1 == r2 && r2 == r3 && r3 == r4 && r4 == r5) {
					System.out.println("SUCCESS: " + s1);
				} else {
					System.out.println("ERROR");
					System.out.println(s1);
					System.out.println(s2);
					System.out.println(s3);
					System.out.println(s4);
					System.out.println(s5);
				}
			}
		}
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_09_BST_Sequences/Question.java
================================================
package Q4_09_BST_Sequences;

import java.util.ArrayList;
import java.util.LinkedList;

import CtCILibrary.TreeNode;

public class Question {
	
	public static void weaveLists(LinkedList<Integer> first, LinkedList<Integer> second, ArrayList<LinkedList<Integer>> results, LinkedList<Integer> prefix) {
		/* One list is empty. Add the remainder to [a cloned] prefix and
		 * store result. */
		if (first.size() == 0 || second.size() == 0) {
			LinkedList<Integer> result = (LinkedList<Integer>) prefix.clone();
			result.addAll(first);
			result.addAll(second);
			results.add(result);
			return;
		}
		
		/* Recurse with head of first added to the prefix. Removing the
		 * head will damage first, so we’ll need to put it back where we
		 * found it afterwards. */
		int headFirst = first.removeFirst();
		prefix.addLast(headFirst);
		weaveLists(first, second, results, prefix);
		prefix.removeLast();
		first.addFirst(headFirst);
		
		/* Do the same thing with second, damaging and then restoring
		 * the list.*/
		int headSecond = second.removeFirst();
		prefix.addLast(headSecond);
		weaveLists(first, second, results, prefix);
		prefix.removeLast();	
		second.addFirst(headSecond);
	}
	
	public static ArrayList<LinkedList<Integer>> allSequences(TreeNode node) {
		ArrayList<LinkedList<Integer>> result = new ArrayList<LinkedList<Integer>>();
		
		if (node == null) {
			result.add(new LinkedList<Integer>());
			return result;
		} 
		
		LinkedList<Integer> prefix = new LinkedList<Integer>();
		prefix.add(node.data);
		
		/* Recurse on left and right subtrees. */
		ArrayList<LinkedList<Integer>> leftSeq = allSequences(node.left);
		ArrayList<LinkedList<Integer>> rightSeq = allSequences(node.right);
		
		/* Weave together each list from the left and right sides. */
		for (LinkedList<Integer> left : leftSeq) {
			for (LinkedList<Integer> right : rightSeq) {
				ArrayList<LinkedList<Integer>> weaved = new ArrayList<LinkedList<Integer>>();
				weaveLists(left, right, weaved, prefix);
				result.addAll(weaved);
			}
		}
		return result;
	}

	public static void main(String[] args) {
		TreeNode node = new TreeNode(100);
		int[] array = {100, 50, 20, 75, 150, 120, 170};
		for (int a : array) {
			node.insertInOrder(a);
		}
		ArrayList<LinkedList<Integer>> allSeq = allSequences(node);
		for (LinkedList<Integer> list : allSeq) {
			System.out.println(list);
		}
		System.out.println(allSeq.size());
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_10_Check_Subtree/QuestionA.java
================================================
package Q4_10_Check_Subtree;

import CtCILibrary.AssortedMethods;
import CtCILibrary.TreeNode;

public class QuestionA {
	
	public static boolean containsTree(TreeNode t1, TreeNode t2) {
		StringBuilder string1 = new StringBuilder();
		StringBuilder string2 = new StringBuilder();
		
		getOrderString(t1, string1);
		getOrderString(t2, string2);
		
		return string1.indexOf(string2.toString()) != -1;
	}
	
	public static void getOrderString(TreeNode node, StringBuilder sb) {
		if (node == null) {
			sb.append("X");             // Add null indicator
			return;
		}
		sb.append(node.data);           // Add root 
		getOrderString(node.left, sb);  // Add left
		getOrderString(node.right, sb); // Add right
	}

	public static void main(String[] args) {
		// t2 is a subtree of t1
		int[] array1 = {1, 2, 1, 3, 1, 1, 5};
		int[] array2 = {2, 3, 1};
		
		TreeNode t1 = AssortedMethods.createTreeFromArray(array1);
		TreeNode t2 = AssortedMethods.createTreeFromArray(array2);

		if (containsTree(t1, t2)) {
			System.out.println("t2 is a subtree of t1");
		} else {
			System.out.println("t2 is not a subtree of t1");
		}

		// t4 is not a subtree of t3
		int[] array3 = {1, 2, 3};
		TreeNode t3 = AssortedMethods.createTreeFromArray(array1);
		TreeNode t4 = AssortedMethods.createTreeFromArray(array3);

		if (containsTree(t3, t4)) {
			System.out.println("t4 is a subtree of t3");
		} else {
			System.out.println("t4 is not a subtree of t3");
		}
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_10_Check_Subtree/QuestionB.java
================================================
package Q4_10_Check_Subtree;

import CtCILibrary.AssortedMethods;
import CtCILibrary.TreeNode;

public class QuestionB {

	public static boolean containsTree(TreeNode t1, TreeNode t2) {
		if (t2 == null) {
			return true; // The empty tree is a subtree of every tree.
		}
		return subTree(t1, t2);
	}
	
	/* Checks if the binary tree rooted at r1 contains the binary tree 
	 * rooted at r2 as a subtree somewhere within it.
	 */
	public static boolean subTree(TreeNode r1, TreeNode r2) {
		if (r1 == null) {
			return false; // big tree empty & subtree still not found.
		} else if (r1.data == r2.data && matchTree(r1,r2)) {
			return true;
		}
		return subTree(r1.left, r2) || subTree(r1.right, r2); 
	}

	/* Checks if the binary tree rooted at r1 contains the 
	 * binary tree rooted at r2 as a subtree starting at r1.
	 */
	public static boolean matchTree(TreeNode r1, TreeNode r2) {
		if (r1 == null && r2 == null) {
			return true; // nothing left in the subtree
		} else if (r1 == null || r2 == null) { 
			return false; // exactly one tree is empty, therefore trees don't match
		} else if (r1.data != r2.data) {  
			return false;  // data doesn't match
		} else {
			return matchTree(r1.left, r2.left) && matchTree(r1.right, r2.right);
		}
	}

	public static void main(String[] args) {
		// t2 is a subtree of t1
		int[] array1 = {1, 2, 1, 3, 1, 1, 5};
		int[] array2 = {2, 3, 1};
		
		TreeNode t1 = AssortedMethods.createTreeFromArray(array1);
		TreeNode t2 = AssortedMethods.createTreeFromArray(array2);

		if (containsTree(t1, t2)) {
			System.out.println("t2 is a subtree of t1");
		} else {
			System.out.println("t2 is not a subtree of t1");
		}

		// t4 is not a subtree of t3
		int[] array3 = {1, 2, 3};
		TreeNode t3 = AssortedMethods.createTreeFromArray(array1);
		TreeNode t4 = AssortedMethods.createTreeFromArray(array3);

		if (containsTree(t3, t4)) {
			System.out.println("t4 is a subtree of t3");
		} else {
			System.out.println("t4 is not a subtree of t3");
		}
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_11_Random_Node/Question.java
================================================
package Q4_11_Random_Node;

public class Question {

	public static void main(String[] args) {
		int[] counts = new int[10];
		for (int i = 0; i < 1000000; i++) {
			Tree tree = new Tree();
			int[] array = {1, 0, 6, 2, 3, 9, 4, 5, 8, 7};
			for (int x : array) {
				tree.insertInOrder(x);
			}
			int d = tree.getRandomNode().data;
			counts[d]++;
		}
		
		for (int i = 0; i < counts.length; i++) {
			System.out.println(i + ": " + counts[i]);
		}
	}

}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_11_Random_Node/Tree.java
================================================
package Q4_11_Random_Node;

import java.util.Random;

public class Tree {
	TreeNode root = null;
	
	public void insertInOrder(int value) {
		if (root == null) {
			root = new TreeNode(value);
		} else {
			root.insertInOrder(value);
		}
	}
	
	public int size() {
		return root == null ? 0 : root.size();
	}
	
	public TreeNode getRandomNode() {
		if (root == null) return null;
		
		Random random = new Random();
		int i = random.nextInt(size());
		return root.getIthNode(i);
	}
}


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_11_Random_Node/TreeNode.java
================================================
package Q4_11_Random_Node;

import java.util.Random;

/* One node of a binary tree. The data element stored is a single 
 * character.
 */
public class TreeNode {
	public int data;      
	public TreeNode left;    
	public TreeNode right; 
	private int size = 0;

	public TreeNode(int d) {
		data = d;
		size = 1;
	}
	
	public void insertInOrder(int d) {
		if (d <= data) {
			if (left == null) {
				left = new TreeNode(d);
			} else {
				left.insertInOrder(d);
			}
		} else {
			if (right == null) {
				right = new TreeNode(d);
			} else {
				right.insertInOrder(d);
			}
		}
		size++;
	}
	
	public int size() {
		return size;
	}
	
	public TreeNode find(int d) {
		if (d == data) {
			return this;
		} else if (d <= data) {
			return left != null ? left.find(d) : null;
		} else if (d > data) {
			return right != null ? right.find(d) : null;
		}
		return null;
	}
	
	public TreeNode getRandomNode() {
		int leftSize = left == null ? 0 : left.size();
		Random random = new Random();
		int index = random.nextInt(size);
		if (index < leftSize) {
			return left.getRandomNode();
		} else if (index == leftSize) {
			return this;
		} else {
			return right.getRandomNode();
		}
	}
	
	public TreeNode getIthNode(int i) {
		int leftSize = left == null ? 0 : left.size();
		if (i < leftSize) {
			return left.getIthNode(i);
		} else if (i == leftSize) {
			return this;
		} else {
			return right.getIthNode(i - (leftSize + 1));
		}
	}
} 


================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_12_Paths_with_Sum/QuestionA.java
================================================
package Q4_12_Paths_with_Sum;

import CtCILibrary.TreeNode;

public class QuestionA {
	
	public static int countPathsWithSum(TreeNode root, int targetSum) {
		if (root == null) return 0;
		
		/* Count paths with sum starting from the root. */
		int pathsFromRoot = countPathsWithSumFromNode(root, targetSum, 0);
		
		/* Try the nodes on the left and right. */
		int pathsOnLeft = countPathsWithSum(root.left, targetSum);
		int pathsOnRight = countPathsWithSum(root.right, targetSum);
		
		return pathsFromRoot + pathsOnLeft + pathsOnRight;
	}
	
	/* Returns the number of paths with this sum starting from this node. */
	public static int countPathsWithSumFromNode(TreeNode node, int targetSum, int currentSum) {
		if (node == null) return 0;
	
		currentSum += node.data;
		
		int totalPaths = 0;
		if (currentSum == targetSum) { // Found a path from the root
			totalPaths++;
		}
		
		totalPaths += countPathsWithSumFromNode(node.left, targetSum, currentSum); // Go left
		totalPaths += countPathsWithSumFromNode(node.right, targetSum, currentSum); // Go right
		
		return totalPaths;
	}	

	public static void main(String [] args) {
		/*
		TreeNode root = new TreeNode(5);
		root.left = new TreeNode(3);		
		root.right = new TreeNode(1);
		root.left.left = new TreeNode(-8);
		root.left.right = new TreeNode(8);
		root.right.left = new TreeNode(2);
		root.right.right = new TreeNode(6);	
		System.out.println(countPathsWithSum(root, 0));*/
		
		/*TreeNode root = new TreeNode(-7);
		root.left = new TreeNode(-7);
		root.left.right = new TreeNode(1);
		root.left.right.left = new TreeNode(2);
		root.right = new TreeNode(7);
		root.right.left = new TreeNode(3);
		root.right.right = new TreeNode(20);
		root.right.right.left = new TreeNode(0);
		root.right.right.left.left = new TreeNode(-3);
		root.right.right.left.left.right = new TreeNode(2);
		root.right.right.left.left.right.left = new TreeNode(1);
		System.out.println(countPathsWithSum(root, -14));*/
		
		TreeNode root = new TreeNode(0);
		root.left = new TreeNode(0);
		root.right = new TreeNode(0);
		root.right.left = new TreeNode(0);
		root.right.left.right = new TreeNode(0);
		root.right.right = new TreeNode(0);
		System.out.println(countPathsWithSum(root, 0));
		System.out.println(countPathsWithSum(root, 4));
	}
}



================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_12_Paths_with_Sum/QuestionB.java
================================================
package Q4_12_Paths_with_Sum;
import java.util.HashMap;

import CtCILibrary.TreeNode;

public class QuestionB {
	
	public static int countPathsWithSum(TreeNode root, int targetSum) {
		return countPathsWithSum(root, targetSum, 0, new HashMap<Integer, Integer>());
	}
	
	public static int countPathsWithSum(TreeNode node, int targetSum, int runningSum, HashMap<Integer, Integer> pathCount) {
		if (node == null) return 0; // Base case
		
		runningSum += node.data;
		
		/* Count paths with sum ending at the current node. */
		int sum = runningSum - targetSum;
		int totalPaths = pathCount.getOrDefault(sum, 0);
		
		/* If runningSum equals targetSum, then one additional path starts at root. Add in this path.*/
		if (runningSum == targetSum) {
			totalPaths++;
		}

		/* Add runningSum to pathCounts. */
		incrementHashTable(pathCount, runningSum, 1);
		
		/* Count paths with sum on the left and right. */
		totalPaths += countPathsWithSum(node.left, targetSum, runningSum, pathCount);
		totalPaths += countPathsWithSum(node.right, targetSum, runningSum, pathCount);
		
		incrementHashTable(pathCount, runningSum, -1); // Remove runningSum
		return totalPaths;
	}
	
	public static void incrementHashTable(HashMap<Integer, Integer> hashTable, int key, int delta) {
		int newCount = hashTable.getOrDefault(key, 0) + delta;
		if (newCount == 0) { // Remove when zero to reduce space usage
			hashTable.remove(key);
		} else {
			hashTable.put(key, newCount);
		}
	}

	public static void main(String [] args) {
		/*
		TreeNode root = new TreeNode(5);
		root.left = new TreeNode(3);		
		root.right = new TreeNode(1);
		root.left.left = new TreeNode(-8);
		root.left.right = new TreeNode(8);
		root.right.left = new TreeNode(2);
		root.right.right = new TreeNode(6);	
		root.right.left.left = new TreeNode(0);	
		System.out.println(countPathsWithSum(root, 0));
		*/
		
		/*TreeNode root = new TreeNode(-7);
		root.left = new TreeNode(-7);
		root.left.right = new TreeNode(1);
		root.left.right.left = new TreeNode(2);
		root.right = new TreeNode(7);
		root.right.left = new TreeNode(3);
		root.right.right = new TreeNode(20);
		root.right.right.left = new TreeNode(0);
		root.right.right.left.left = new TreeNode(-3);
		root.right.right.left.left.right = new TreeNode(2);
		root.right.right.left.left.right.left = new TreeNode(1);
		System.out.println(countPathsWithSum(root, 0));*/
		
		TreeNode root = new TreeNode(0);
		root.left = new TreeNode(0);
		root.right = new TreeNode(0);
		root.right.left = new TreeNode(0);
		root.right.left.right = new TreeNode(0);
		root.right.right = new TreeNode(0);
		System.out.println(countPathsWithSum(root, 0));
		System.out.println(countPathsWithSum(root, 4));
	}
}



================================================
FILE: Java/Ch 04. Trees and Graphs/Q4_12_Paths_with_Sum/Tester.java
================================================
package Q4_12_Paths_with_Sum;

import CtCILibrary.AssortedMethods;
import CtCILibrary.TreeNode;

public class Tester {

	public static void main(String[] args) {
		boolean isWorking = true;
		while (isWorking) {
			int min = -20;
			int max = 20;
			int size = 20;
			TreeNode root = AssortedMethods.randomBST(size, min, max);
		
			for (int targetSum = Math.min(-1, min * size - 10); targetSum <= Math.max(100, max * size + 10); targetSum++) {
				int answerA = QuestionA.countPathsWithSum(root, targetSum);
				int answerB = QuestionB.countPathsWithSum(root, targetSum);
				if (answerA > 0 || answerB > 0) {
					System.out.println(targetSum + ": " + answerA + ", " + answerB + " | " + (answerA == answerB));
				}
				if (answerA != answerB) {
					isWorking = false;
					break;
				}
			}
		}
	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_01_Insertion/Question.java
================================================
package Q5_01_Insertion;

import CtCILibrary.AssortedMethods;

public class Question {

	public static int updateBits(int n, int m, int i, int j) {
		// Validation
		if (i > j || i < 0 || j >= 32) {
			return 0;
		}
		
		/* Create a mask to clear bits i through j in n
		/* EXAMPLE: i = 2, j = 4. Result should be 11100011.
		 * (Using 8 bits for this example.  This is obviously not actually 8 bits.)
		 */
		int allOnes = ~0; // allOnes = 11111111
		
		int left = j < 31 ? (allOnes << (j + 1)) : 0; // 1s until position j, then 0s. left = 11100000	
	  	int right = ((1 << i) - 1); // 1s after position i.  right = 00000011
		int mask = left | right; // All 1s, except for 0s between i and j. mask = 11100011

		/* Clear i through j, then put m in there */
		int n_cleared = n & mask; // Clear bits j through i.
		int m_shifted = m << i; // Move m into correct position.
		
		/* OR them, and we're done! */
		return n_cleared | m_shifted; 
	}
	
	public static void main(String[] args) {
		int a = ~23423;
		System.out.println(AssortedMethods.toFullBinaryString(a));
		int b = 5;
		System.out.println(AssortedMethods.toFullBinaryString(b));		
		int c = updateBits(a, b, 29, 31);
		System.out.println(AssortedMethods.toFullBinaryString(c));
	}
}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_02_Binary_to_String/Question.java
================================================
package Q5_02_Binary_to_String;

public class Question {
	public static String printBinary(double num) {
		if (num >= 1 || num <= 0) {
			return "ERROR";
		}
	
		StringBuilder binary = new StringBuilder();
		binary.append(".");
		while (num > 0) {
			/* Setting a limit on length: 32 characters */
			if (binary.length() > 32) {
				return "ERROR";
			}
			double r = num * 2;
			if (r >= 1) {
				binary.append(1);
				num = r - 1;
			} else {
				binary.append(0);
				num = r;
			}
		}
		return binary.toString();
	}
	
	public static String printBinary2(double num) {
		if (num >= 1 || num <= 0) {
			return "ERROR";
		}
	
		StringBuilder binary = new StringBuilder();
		double frac = 0.5;
		binary.append(".");
		while (num > 0) {
			/* Setting a limit on length: 32 characters */
			if (binary.length() >= 32) {
				return "ERROR";
			}
			if (num >= frac) {
				binary.append(1);
				num -= frac;
			} else {
				binary.append(0);
			}
			frac /= 2;
		}
		return binary.toString();
	}	
	
	public static void main(String[] args) {
		String bs = printBinary(.125);
		System.out.println(bs);
		
		for (int i = 0; i < 1000; i++) {
			double num = i / 1000.0;
			String binary = printBinary(num);
			String binary2 = printBinary2(num);
			if (!binary.equals("ERROR") || !binary2.equals("ERROR")) {
				System.out.println(num + " : " + binary + " " + binary2);
			}
		}
	}
}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/QuestionA.java
================================================
package Q5_03_Flip_Bit_to_Win;

public class QuestionA {
	
	public static int SEQUENCE_LENGTH = 32;
	
	public static boolean getBit(int num, int i) {
		return ((num & (1 << i)) != 0);
	}	
	
	public static int longestSequence(int n) {
		int maxSeq = 0;
		
		for (int i = 0; i < SEQUENCE_LENGTH; i++) {
			maxSeq = Math.max(maxSeq,  longestSequenceOf1s(n, i));
		}
		
		return maxSeq;
	}
	
	public static int longestSequenceOf1s(int n, int indexToIgnore) {
		int max = 0;
		int counter = 0;
		for (int i = 0; i < SEQUENCE_LENGTH; i++) {
			if (i == indexToIgnore || getBit(n, i)) {
				counter++;
				max = Math.max(counter, max);
			} else {
				counter = 0;
			}
		}
		return max;
	}	
	
	public static void main(String[] args) {
		int original_number = Integer.MAX_VALUE;
		int new_number = longestSequence(original_number);
			
		System.out.println(Integer.toBinaryString(original_number));
		System.out.println(new_number);			
	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/QuestionB.java
================================================
package Q5_03_Flip_Bit_to_Win;

import java.util.ArrayList;

public class QuestionB {
	
	public static int longestSequence(int n) {
		if (n == -1) return Integer.BYTES * 8;
		ArrayList<Integer> sequences = getAlternatingSequences(n);
		return findLongestSequence(sequences);
	}	
	
	/* Return a list of the sizes of the sequences. The sequence starts 
	 * off with the number of 0s (which might be 0) and then alternates
	 * with the counts of each value.*/
	public static ArrayList<Integer> getAlternatingSequences(int n) {
		ArrayList<Integer> sequences = new ArrayList<Integer>();
		
		int searchingFor = 0;
		int counter = 0;
		
		for (int i = 0; i < Integer.BYTES * 8; i++) {
			if ((n & 1) != searchingFor) {
				sequences.add(counter);
				searchingFor = n & 1; // Flip 1 to 0 or 0 to 1
				counter = 0;	
			}
			counter++;
			n >>>= 1;
		}
		sequences.add(counter);
		
		return sequences;
	}
	
	public static int findLongestSequence(ArrayList<Integer> seq) {
		int maxSeq = 1;
		
		for (int i = 0; i < seq.size(); i += 2) {
			int zerosSeq = seq.get(i);
			int onesSeqPrev = i - 1 >= 0 ? seq.get(i - 1) : 0;
			int onesSeqNext = i + 1 < seq.size() ? seq.get(i + 1) : 0;
			
			int thisSeq = 0;
			if (zerosSeq == 1) { // Can merge
				thisSeq = onesSeqNext + 1 + onesSeqPrev; 
			} else if (zerosSeq > 1) { // Just add a one to either side
				thisSeq = 1 + Math.max(onesSeqPrev, onesSeqNext);
			} else if (zerosSeq == 0) { // No zero, but take either side
				thisSeq = Math.max(onesSeqPrev, onesSeqNext);
			}
			maxSeq = Math.max(thisSeq, maxSeq);
		}
		
		return maxSeq;
	}	
	
	public static void main(String[] args) {
		int original_number = 1775;
		int new_number = longestSequence(original_number);
			
		System.out.println(Integer.toBinaryString(original_number));
		System.out.println(new_number);
	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/QuestionC.java
================================================
package Q5_03_Flip_Bit_to_Win;

public class QuestionC {

	public static int SEQUENCE_LENGTH = 32;
	
	/* Given set of three sequences ordered as {0s, then 1s, then 0s}, 
	 * find max sequence that can be formed. */
	public static int getMaxSequence(int[] sequences) { /* 1s, then 0s, then [old] ones */
		if (sequences[1] == 1) { // a single 0 -> merge sequences
			return sequences[0] + sequences[2] + 1; 
		} else if (sequences[1] == 0) { // no 0s -> take one side
			return Math.max(sequences[0], sequences[2]); 
		} else {  // many 0s -> take side, add 1 (flip a bit)
			return Math.max(sequences[0], sequences[2]) + 1;
		}
	}
	
	public static void shift(int[] sequences) {
		sequences[2] = sequences[1];
		sequences[1] = sequences[0];
		sequences[0] = 0;
	}
	
	public static int longestSequence(int n) {
		int searchingFor = 0;
		int[] sequences = {0, 0, 0}; // Counts of last 3 sequences
		int maxSequence = 1;
		
		for (int i = 0; i < SEQUENCE_LENGTH; i++) {
			if ((n & 1) != searchingFor) {
				if (searchingFor == 1) { // End of 1s + 0s + 1s sequence
					maxSequence = Math.max(maxSequence, getMaxSequence(sequences));
				}
				
				searchingFor = n & 1; // Flip 1 to 0 or 0 to 1
				shift(sequences); // Shift sequences
			}
			sequences[0]++;
			n >>>= 1;
		}
		
		/* Check final set of sequences */
		if (searchingFor == 0) {
			shift(sequences);		
		}
		int finalSequence = getMaxSequence(sequences);
		maxSequence = Math.max(finalSequence, maxSequence);		
		
		return maxSequence;
	}		
	
	public static void main(String[] args) {
		int original_number = Integer.MAX_VALUE;
		int new_number = longestSequence(original_number);
			
		System.out.println(Integer.toBinaryString(original_number));
		System.out.println(new_number);		
	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/QuestionD.java
================================================
package Q5_03_Flip_Bit_to_Win;

public class QuestionD {

	public static int flipBit(int a) {
		/* If all 1s, this is already the longest sequence. */
		if (~a == 0) return Integer.BYTES * 8;
		
		int currentLength = 0;
		int previousLength = 0;
		int maxLength = 1; // We can always have a sequence of at least one 1
		while (a != 0) {
			if ((a & 1) == 1) {
				currentLength++;
			} else if ((a & 1) == 0) {
				/* Update to 0 (if next bit is 0) or currentLength (if next bit is 1). */
				previousLength = (a & 2) == 0 ? 0 : currentLength;
				currentLength = 0;
			}
			maxLength = Math.max(previousLength + currentLength + 1, maxLength);
			a >>>= 1;
		}
		return maxLength;
	}
	
	public static void main(String[] args) {
		int[][] cases = {{-1, 32}, {Integer.MAX_VALUE, 32}, {-10, 31}, {0, 1}, 
				{1, 2}, {15, 5}, {1775, 8}};
		for (int[] c : cases) {
			int x = flipBit(c[0]);
			boolean r = (c[1] == x);
			System.out.println(c[0] + ": " + x + ", " + c[1] + " " + r);
		}

	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/Tester.java
================================================
package Q5_03_Flip_Bit_to_Win;

public class Tester {
	
	public static boolean checkRange(int start, int range) {
		for (int i = 0; i < range; i++) {
			int value = start + i;
			int seqA = QuestionA.longestSequence(value);
			int seqB = QuestionB.longestSequence(value);
			int seqC = QuestionC.longestSequence(value);
			int seqD = QuestionC.longestSequence(value);
			
			if (seqA != seqB || seqB != seqC || seqC != seqD) {
				System.out.println("FAILURE on value " + value);
				String xs = Integer.toBinaryString(value);
				System.out.println(xs);
				System.out.println("A: " + seqA);
				System.out.println("B: " + seqB);
				System.out.println("C: " + seqC);
				System.out.println("D: " + seqD);
				return false;
			} 
		}
		return true;
	}
	
	public static void main(String[] args) {
		int[][] ranges = {{Integer.MIN_VALUE, 1000}, {Integer.MAX_VALUE - 2333, 5333},
				{-10000, 20000}};
		for (int[] range : ranges) {
			if (!checkRange(range[0], range[1])) {
				System.out.println("ERROR");
			} else {
				int end = range[0] + range[1];
				System.out.println("SUCCESS: " + range[0] + " -> " + end);
			}
		}
	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_04_Next_Number/QuestionA.java
================================================
package Q5_04_Next_Number;

public class QuestionA {

	public static int countOnes(int i) {
		int count = 0;
		while (i > 0) {
			if ((i & 1) == 1) {
				count++;
			}
			i = i >> 1;
		}
		return count;
	}
	
	public static int countZeros(int i) {
		return 32 - countOnes(i);
	}	
	
	public static boolean hasValidNext(int i) {
		if (i == 0) {
			return false;
		}
		int count = 0;
		while ((i & 1) == 0) {
			i >>= 1;
			count++;
		}
		while ((i & 1) == 1) {
			i >>= 1;
			count++;
		}		
		if (count == 31) {
			return false;
		}
		return true;	
	}
	
	public static boolean hasValidPrev(int i) {
		while ((i & 1) == 1) {
			i >>= 1;
		}
		if (i == 0) {
			return false;
		}
		return true;		
	}

	public static int getNextSlow(int i) {
		if (!hasValidNext(i)) {
			return -1;
		}
		int num_ones = countOnes(i);
		i++;
		while (countOnes(i) != num_ones) {
			i++;
		}
		return i;
	}

	public static int getPrevSlow(int i) {
		if (!hasValidPrev(i)) {
			return -1;
		}		
		int num_ones = countOnes(i);
		i--;
		while (countOnes(i) != num_ones) {
			i--;
		}
		return i;
	}
	
	public static void main(String[] args) {
		int i = 13948;
		int p1 = getPrevSlow(i);
		int n1 = getNextSlow(i);
		Tester.binPrint(p1);
		Tester.binPrint(n1);
	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_04_Next_Number/QuestionB.java
================================================
package Q5_04_Next_Number;

public class QuestionB {
	
	public static int getNext(int n) {
		int c = n;
		int c0 = 0;
		int c1 = 0;
		while (((c & 1) == 0) && (c != 0)) {
			c0++;
			c >>= 1;
		}
		
		while ((c & 1) == 1) {
			c1++;
			c >>= 1;
		}
		
		/* If c is 0, then n is a sequence of 1s followed by a sequence of 0s. This is already the biggest
		 * number with c1 ones. Return error.
		 */
		if (c0 + c1 == 31 || c0 + c1 == 0) {
			return -1;
		}
		
		int pos = c0 + c1; // position of right-most non-trailing zero (where the right most bit is bit 0)
		
		/* Flip the right-most non-trailing zero (which will be at position pos) */
		n |= (1 << pos); // Flip right-most non-trailing zero
				
		/* Clear all bits to the right of pos.
		 * Example with pos = 5 
		 * (1) Shift 1 over by 5 to create 0..0100000           [ mask = 1 << pos ]
		 * (2) Subtract 1 to get 0..0011111                     [ mask = mask - 1 ]
		 * (3) Flip all the bits by using '~' to get 1..1100000 [ mask = ~mask    ]
		 * (4) AND with n
		 */
		n &= ~((1 << pos) - 1); // Clear all bits to the right of pos
		
		/* Put (ones-1) 1s on the right by doing the following:
		 * (1) Shift 1 over by (ones-1) spots. If ones = 3, this gets you 0..0100
		 * (2) Subtract one from that to get 0..0011
		 * (3) OR with n
		 */
		n |= (1 << (c1 - 1)) - 1;
		
		return n;
	}
	
	public static int getPrev(int n) {
		int temp = n;
		int c0 = 0;
		int c1 = 0;
		while ((temp & 1) == 1) {
			c1++;
			temp >>= 1;
		}
		
		/* If temp is 0, then the number is a sequence of 0s followed by a sequence of 1s. This is already
		 * the smallest number with c1 ones. Return -1 for an error.
		 */
		if (temp == 0) { 
			return -1;
		}
		
		while (((temp & 1) == 0) && (temp != 0)) {
			c0++;
			temp >>= 1;
		}

		int p = c0 + c1; // position of right-most non-trailing one (where the right most bit is bit 0)

		/* Flip right-most non-trailing one. 
		 * Example: n = 00011100011.
		 * c1 = 2
		 * c0 = 3
		 * pos = 5
		 * 
		 * Build up a mask as follows:
		 * (1) ~0 will be a sequence of 1s
		 * (2) shifting left by p + 1 will give you 11.111000000 (six 0s) 
		 * (3) ANDing with n will clear the last 6 bits
		 * n is now 00011000000
		 */
		n &= ((~0) << (p + 1)); // clears from bit p onwards (to the right)
		
		/* Create a sequence of (c1+1) 1s as follows
		 * (1) Shift 1 to the left (c1+1) times. If c1 is 2, this will give you 0..001000
		 * (2) Subtract one from that. This will give you 0..00111
		 */
		int mask = (1 << (c1 + 1)) - 1; // Sequence of (c1+1) ones
		
		/* Move the ones to be right up next to bit p 
		 * Since this is a sequence of (c1+1) ones, and p = c1 + c0, we just need to
		 * shift this over by (c0-1) spots.
		 * If c0 = 3 and c1 = 2, then this will look like 00...0011100
		 * 
		 * Then, finally, we OR this with n.
		 */
		n |= mask << (c0 - 1);  
		
		return n;		
	}	
	
	public static void binPrint(int i) {
		System.out.println(i + ": " + Integer.toBinaryString(i));		
	}
	
	public static void main(String[] args) {
		int i = 13948;
		int p1 = getPrev(i);
		int n1 = getNext(i);
		Tester.binPrint(p1);
		Tester.binPrint(n1);
	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_04_Next_Number/QuestionC.java
================================================
package Q5_04_Next_Number;

public class QuestionC {
	public static int getNextArith(int n) {
		int c = n;
		int c0 = 0;
		int c1 = 0;
		while (((c & 1) == 0) && (c != 0)) {
			c0++;
			c >>= 1;
		}
		
		while ((c & 1) == 1) {
			c1++;
			c >>= 1;
		}
		
		/* If c is 0, then n is a sequence of 1s followed by a sequence of 0s. This is already the biggest
		 * number with c1 ones. Return error.
		 */
		if (c0 + c1 == 31 || c0 + c1 == 0) {
			return -1;
		}
		
		/* Arithmetically:
		 * 2^c0 = 1 << c0
		 * 2^(c1-1) = 1 << (c0 - 1)
		 * next = n + 2^c0 + 2^(c1-1) - 1;
		 */
		
		return n + (1 << c0) + (1 << (c1 - 1)) - 1;
	}
	
	public static int getPrevArith(int n) {
		int temp = n;
		int c0 = 0;
		int c1 = 0;
		while (((temp & 1) == 1) && (temp != 0)) {
			c1++;
			temp >>= 1;
		}
		
		/* If temp is 0, then the number is a sequence of 0s followed by a sequence of 1s. This is already
		 * the smallest number with c1 ones. Return -1 for an error.
		 */
		if (temp == 0) { 
			return -1;
		}
		
		while ((temp & 1) == 0 && (temp != 0)) {
			c0++;
			temp >>= 1;
		}

		/* Arithmetic:
		 * 2^c1 = 1 << c1
		 * 2^(c0 - 1) = 1 << (c0 - 1)
		 */
		return n - (1 << c1) - (1 << (c0 - 1)) + 1;		
	}	
	
	public static void binPrint(int i) {
		System.out.println(i + ": " + Integer.toBinaryString(i));		
	}
	
	public static void main(String[] args) {
		int i = 13948;
		int p1 = getPrevArith(i);
		int n1 = getNextArith(i);
		Tester.binPrint(p1);
		Tester.binPrint(n1);
	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_04_Next_Number/Tester.java
================================================
package Q5_04_Next_Number;

public class Tester {
	public static void binPrint(int i) {
		System.out.println(i + ": " + Integer.toBinaryString(i));		
	}
	
	public static void main(String[] args) {
		for (int i = 0; i < 200; i++) {
			int p1 = QuestionA.getPrevSlow(i);
			int p2 = QuestionB.getPrev(i);
			int p3 = QuestionC.getPrevArith(i);
			
			int n1 = QuestionA.getNextSlow(i);
			int n2 = QuestionB.getNext(i);
			int n3 = QuestionC.getNextArith(i);
			
			if (p1 != p2 || p2 != p3 || n1 != n2 || n2 != n3) {
				binPrint(i);
				binPrint(p1);
				binPrint(p2);
				binPrint(p3);
				binPrint(n1);
				binPrint(n2);
				binPrint(n3);
				System.out.println("");
				break;
			}			
		}
		System.out.println("Done!");
	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_06_Conversion/QuestionA.java
================================================
package Q5_06_Conversion;

import CtCILibrary.AssortedMethods;

public class QuestionA {
	public static int bitSwapRequired(int a, int b) {
		int count = 0;
		int c = a ^ b;
		while (c != 0) {
			count += c & 1; // Increment count if c ends with a 1
			c >>>= 1; // Shift right by 1
		}
		return count;
	}
	
	public static void main(String[] args) {
		int a = -23432;
		int b = 512132;
		System.out.println(a + ": " + AssortedMethods.toFullBinaryString(a));
		System.out.println(b + ": " + AssortedMethods.toFullBinaryString(b));
		System.out.println("Required number of bits: " + bitSwapRequired(a, b));
	}
}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_06_Conversion/QuestionB.java
================================================
package Q5_06_Conversion;

import CtCILibrary.AssortedMethods;

public class QuestionB {
	public static int bitSwapRequired(int a, int b){
		int count = 0;
		int c = a ^ b;

		System.out.println("****");
		System.out.println(c + ": " + AssortedMethods.toFullBinaryString(c));
		while (c != 0) {
			System.out.println("c - 1: " + c + ": " + AssortedMethods.toFullBinaryString(c - 1));
			c = c & (c-1);
			System.out.println("c: " + c + ": " + AssortedMethods.toFullBinaryString(c));
			count++;
			System.out.println("****");
		}
		return count;
	}
	
	public static void main(String[] args) {
		int a = -23432;
		int b = 512132;
		System.out.println(a + ": " + AssortedMethods.toFullBinaryString(a));
		System.out.println(b + ": " + AssortedMethods.toFullBinaryString(b));
		System.out.println("Required number of bits: " + bitSwapRequired(a, b));
	}
}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_06_Conversion/Tester.java
================================================
package Q5_06_Conversion;

import CtCILibrary.AssortedMethods;

public class Tester {
	public static int bitSwapRequired(int a, int b) {
		int count = 0;
		for (int c = a ^ b; c != 0; c = c >>> 1) { 
			count += c & 1;
		}
		return count;
	}
	
	public static int bitSwapRequired2(int a, int b){
		int count = 0;
		for (int c = a ^ b; c != 0; c = c & (c-1)) {
			count++;
		}
		return count;
	}
	
	public static void main(String[] args) {
		int a = -23432;
		int b = 512132;
		System.out.println(a + ": " + AssortedMethods.toFullBinaryString(a));
		System.out.println(b + ": " + AssortedMethods.toFullBinaryString(b));
		int nbits = QuestionA.bitSwapRequired(a, b);
		int nbits2 = QuestionB.bitSwapRequired(a, b);
		System.out.println("Required number of bits: " + nbits + " " + nbits2);
	}
}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_07_Pairwise_Swap/Question.java
================================================
package Q5_07_Pairwise_Swap;

import CtCILibrary.AssortedMethods;

public class Question {

	public static int swapOddEvenBits(int x) { 
		return ( ((x & 0xaaaaaaaa) >>> 1) | ((x & 0x55555555) << 1) ); 
	}
	
	public static void main(String[] args) {
		int a = 234321;
		System.out.println(a + ": " + AssortedMethods.toFullBinaryString(a));
		int b = swapOddEvenBits(a);
		System.out.println(b + ": " + AssortedMethods.toFullBinaryString(b));
	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Q5_08_Draw_Line/Question.java
================================================
package Q5_08_Draw_Line;

public class Question {
	public static int computeByteNum(int width, int x, int y) {
		return (width * y + x) / 8;
	}
	
	public static void drawLine(byte[] screen, int width, int x1, int x2, int y) {
		int start_offset = x1 % 8;
		int first_full_byte = x1 / 8;
		if (start_offset != 0) {
			first_full_byte++;
		}
		
		int end_offset = x2 % 8;
		int last_full_byte = x2 / 8;
		if (end_offset != 7) {
			last_full_byte--;
		}
		
		// Set full bytes
		for (int b = first_full_byte; b <= last_full_byte; b++) {
			screen[(width / 8) * y + b] = (byte) 0xFF;
		}
		
		byte start_mask = (byte) (0xFF >> start_offset);
		byte end_mask = (byte) ~(0xFF >> (end_offset + 1));
		
		// Set start and end of line
		if ((x1 / 8) == (x2 / 8)) { // If x1 and x2 are in the same byte
			byte mask = (byte) (start_mask & end_mask);
			screen[(width / 8) * y + (x1 / 8)] |= mask;
		} else {
			if (start_offset != 0) {
				int byte_number = (width / 8) * y + first_full_byte - 1;
				screen[byte_number] |= start_mask;
			}
			if (end_offset != 7) {
				int byte_number = (width / 8) * y + last_full_byte + 1;
				screen[byte_number] |= end_mask;
			} 
		}
	}
	
	public static void printByte(byte b) {
		for (int i = 7; i >= 0; i--) {
			char c = ((b >> i) & 1) == 1 ? '1' : '_';
			System.out.print(c);
		}
	}
	
	public static void printScreen(byte[] screen, int width) {
		int height = screen.length * 8 / width;
		for (int r = 0; r < height; r++) {
			for (int c = 0; c < width; c+=8) {
				byte b = screen[computeByteNum(width, c, r)];
				printByte(b);
			}
			System.out.println("");
		}
	}
	
	public static void main(String[] args) {
		int width = 8 * 1;
		int height = 1;
		for (int r = 0; r < height; r++) {
			for (int c1 = 0; c1 < width; c1++) {
				for (int c2 = c1; c2 < width; c2++) {
					byte[] screen = new byte[width * height / 8];

					System.out.println("row: " + r + ": " + c1 + " -> " + c2);
					drawLine(screen, width, c1, c2, r);
					printScreen(screen, width);
					System.out.println("\n\n");
				}
			}
		}

	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Sample_Code/RightShifts.java
================================================
package Sample_Code;

import CtCILibrary.AssortedMethods;

public class RightShifts {
	public static int repeatedArithmeticShift(int x, int count) {
		for (int i = 0; i < count; i++) {
			x >>= 1; // Arithmetic shift by 1
		}
		return x;
	}
	
	public static int repeatedLogicalShift(int x, int count) {
		for (int i = 0; i < count; i++) {
			x >>>= 1; // Logical shift by 1
		}
		return x;
	}	
	
	public static void main(String[] args) {
		for (int i = 8; i >= -8; i--) {
			System.out.println(AssortedMethods.toFullBinaryString(i) + ": " + i);
		}
		
		int x = -93242;
		int resultArithmetic = repeatedArithmeticShift(x, 40);
		int resultLogical = repeatedLogicalShift(x, 40);
		System.out.println(AssortedMethods.toFullBinaryString(resultArithmetic) + ": " + resultArithmetic);
		System.out.println(AssortedMethods.toFullBinaryString(resultLogical) + ": " + resultLogical);
	}

}


================================================
FILE: Java/Ch 05. Bit Manipulation/Sample_Code/Sample_Code.java
================================================
package Sample_Code;

import CtCILibrary.AssortedMethods;

public class Sample_Code {

	public static boolean getBit(int num, int i) {
		return ((num & (1 << i)) != 0);
	}
	
	public static int setBit(int num, int i) {
		return num | (1 << i);
	}
	
	public static int clearBit(int num, int i) {
		int mask = ~(1 << i);
		return num & mask;
	}
	
	public static int updateBit(int num, int i, boolean bitIs1) {
		int value = bitIs1 ? 1 : 0;
		int mask = ~(1 << i);
		return (num & mask) | (value << i);
	}
	
	public static int clearBitsMSBthroughI(int num, int i) {
		int mask = (1 << i) - 1;
		return num & mask;
	}
	
	public static int clearBitsIthrough0(int num, int i) {
		int mask = (-1 << (i+1));
		return num & mask;
	}
	
	public static void main(String[] args) {
		
		int number = 59;
		System.out.println("Testing with number: " + number);
		
		// Get Bit
		System.out.println("Get Bit");
		System.out.println(AssortedMethods.toFullBinaryString(number));
		for (int i = 31; i >= 0; i--) {
			int res = getBit(number, i) ? 1 : 0;
			System.out.print(res);
		}
		
		// Update Bit
		System.out.println("\n\nUpdate Bit");		
		int num1 = 1578; // arbitrary number
		for (int i = 31; i >= 0; i--) {
			num1 = updateBit(num1, i, getBit(number, i));
		}	
		System.out.println(num1);
		
		// Set and Clear Bit
		System.out.println("\nSet and Clear Bit");		
		int num2 = 1578; // arbitrary number
		for (int i = 31; i >= 0; i--) {
			if (getBit(number, i)) {
				num2 = setBit(num2, i);
			} else {
				num2 = clearBit(num2, i);
			}
		}	
		System.out.println(num2);
	
		// Clear Bits MSB through i
		number = 13242352;
		int clearMSBThrough = 4;
		System.out.println("\nClear bits MSB through " + clearMSBThrough);	
		System.out.println(AssortedMethods.toFullBinaryString(number));
		int num3 = clearBitsMSBthroughI(number, clearMSBThrough);
		System.out.println(AssortedMethods.toFullBinaryString(num3));
		
		// Clear Bits i through 0
		int clearToLSB = 2;
		System.out.println("\nClear bits " + clearToLSB + " through 0");	
		number = -1;
		System.out.println(AssortedMethods.toFullBinaryString(number));
		int num4 = clearBitsIthrough0(number, clearToLSB);
		System.out.println(AssortedMethods.toFullBinaryString(num4));
	}

}


================================================
FILE: Java/Ch 06. Math and Logic Puzzles/Introduction/PrimeNumbers.java
================================================
package Introduction;

public class PrimeNumbers {

	public static boolean primeNaive(int n) {
		for (int i = 2; i < n; i++) {
			if (n % i == 0) {
				return false;
			}
		}
		return true;
	}
	
	public static boolean primeSlightlyBetter(int n) {
		int sqrt = (int) Math.sqrt(n);
		for (int i = 2; i <= sqrt; i++) {
			if (n % i == 0) {
				return false;
			}
		}
		return true;
	}	
	
	public static void main(String[] args) {
		for (int i = 2; i < 100; i++) {
			if (primeSlightlyBetter(i)) {
				System.out.println(i);
			}
		}
	}

}


================================================
FILE: Java/Ch 06. Math and Logic Puzzles/Introduction/SieveOfEratosthenes.java
================================================
package Introduction;

public class SieveOfEratosthenes {
	
	public static void crossOff(boolean[] flags, int prime) {
		/* Cross off remaining multiples of prime. We can start with
		 * (prime*prime), because if we have a k * prime, where k < prime,
		 * this value would have already been crossed off in a prior
		 * iteration. */		
		for (int i = prime * prime; i < flags.length; i += prime) {
			flags[i] = false;
		}
	}
	
	public static int getNextPrime(boolean[] flags, int prime) {
		int next = prime + 1;
		while (next < flags.length && !flags[next]) {
			next++;
		}
		return next;	
	}
	
	public static void init(boolean[] flags) {
		flags[0] = false;
		flags[1] = false;
		for (int i = 2; i < flags.length; i++) {
			flags[i] = true;
		}
	}
	
	public static int[] prune(boolean[] flags, int count) {
		int[] primes = new int[count];
		int index = 0;
		for (int i = 0; i < flags.length; i++) {
			if (flags[i]) {
				primes[index] = i;
				index++;
			}
		}
		return primes;
	}
	
	public static boolean[] sieveOfEratosthenes(int max) {
        boolean[] flags = new boolean[max + 1];
        
		init(flags);
        int prime = 2;
        
        while (prime <= Math.sqrt(max)) {       	
    		/* Cross off remaining multiples of prime */   
    		crossOff(flags, prime); 

    		/* Find next value which is true */
    		prime = getNextPrime(flags, prime);
        }
        
        return flags; //prune(flags, count);
	}
	
	public static void main(String[] args) {
		boolean[] primes = sieveOfEratosthenes(4);
		for (int i = 0; i < primes.length; i++) {
			if (primes[i]) {
				System.out.println(i);
			}
		}
	}

}


================================================
FILE: Java/Ch 06. Math and Logic Puzzles/Q6_05_Egg_Drop/Question.java
================================================
package Q6_05_Egg_Drop;

public class Question {
	public static int breakingPoint = 89;
	public static int countDrops = 0;


	public static boolean willBreak(int floor) {
		countDrops++;
		return floor >= breakingPoint;
	}


	public static int findBreakingPoint(int floors) {
		int interval = 14;
		int previousFloor = 0;
		int egg1 = interval;
		
		/* Drop egg1 at decreasing intervals. */
		while (!willBreak(egg1) && egg1 <= floors) {
			interval -= 1;
			previousFloor = egg1;
			egg1 += interval;
		}
		
		/* Drop egg2 at 1 unit increments. */
		int egg2 = previousFloor + 1;
		while (egg2 < egg1 && egg2 <= floors && !willBreak(egg2)) {
			egg2 += 1;
		}
		
		/* If it didn’t break, return -1. */
		return egg2 > floors ? -1 : egg2;
	}


	public static void main(String[] args) {
		int max = 0;
		for (int i = 1; i <= 100; i++) {
			countDrops = 0;
			breakingPoint = i;
			int bp = findBreakingPoint(100);
			
			if (bp == breakingPoint) {
				System.out.println("SUCCESS: " + i + " -> " + bp + " -> " + countDrops);
			} else {
				System.out.println("ERROR: " + i + " -> " + bp + " vs " + breakingPoint);
				break;
			}
			max = countDrops > max ? countDrops : max;
		}
		System.out.println(max);
	}
}



================================================
FILE: Java/Ch 06. Math and Logic Puzzles/Q6_07_The_Apocalypse/Question.java
================================================
package Q6_07_The_Apocalypse;

import java.util.Random;

public class Question {
	public static int[] runOneFamily() {
		Random random = new Random();
		int boys = 0;
		int girls = 0;
		while (girls == 0) { // until we have a girl
			if (random.nextBoolean()) { // girl
				girls += 1;
			} else { // boy
				boys += 1;
			}
		}
		int[] genders = {girls, boys};
		return genders;
	}
	
	public static double runNFamilies(int n) {
		int boys = 0;
		int girls = 0;
		for (int i = 0; i < n; i++) {
			int[] genders = runOneFamily();
			girls += genders[0];
			boys += genders[1];
		}
		return girls / (double) (boys + girls); 
	}
	
	public static void main(String[] args) {
		double ratio = runNFamilies(10000000);
		System.out.println(ratio);

	}

}


================================================
FILE: Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/Bottle.java
================================================
package Q6_10_Test_Strips;

public class Bottle {
	private boolean poisoned = false;
	private int id;
	
	public Bottle(int id) {
		this.id = id;
	}
	
	public int getId() {
		return id;
	}
	
	public void setAsPoisoned() {
		poisoned = true;
	}
	
	public boolean isPoisoned() {
		return poisoned;
	}
}


================================================
FILE: Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/QuestionA.java
================================================
package Q6_10_Test_Strips;

import java.util.ArrayList;
import java.util.Random;

public class QuestionA {
	public static int findPoisonedBottle(ArrayList<Bottle> bottles, ArrayList<TestStrip> strips) {
		int today = 0;
		
		while (bottles.size() > 1 && strips.size() > 0) {
			/* Run tests. */
			runTestSet(bottles, strips, today);
			
			/* Wait for results. */
			today += TestStrip.DAYS_FOR_RESULT;
			
			/* Check results. */
			for (TestStrip strip : strips) {
				if (strip.isPositiveOnDay(today)) {
					bottles = strip.getLastWeeksBottles(today);
					strips.remove(strip);
					break;
				}
			}
		}
	
		if (bottles.size() == 1) {
			System.out.println("Suspected bottle is " + bottles.get(0).getId() + " on day " + today);
			return bottles.get(0).getId();
		}
		return -1;	
	}	
	
	public static void runTestSet(ArrayList<Bottle> bottles, ArrayList<TestStrip> strips, int day) {
		int index = 0;
		for (Bottle bottle : bottles) {
			TestStrip strip = strips.get(index);
			strip.addDropOnDay(day, bottle);
			index = (index + 1) % strips.size();
		}
	}
	
	public static ArrayList<Bottle> createBottles(int nBottles, int poisoned) {
		ArrayList<Bottle> bottles = new ArrayList<Bottle>();
		for (int i = 0; i < nBottles; i++) {
			bottles.add(new Bottle(i));
		}
		
		if (poisoned == -1) {
			Random random = new Random();
			poisoned = random.nextInt(nBottles);
		}
		bottles.get(poisoned).setAsPoisoned();
		
		System.out.println("Added poison to bottle " + poisoned);
		
		return bottles;
	}
	
	public static ArrayList<TestStrip> createTestStrips(int nTestStrips) {
		ArrayList<TestStrip> testStrips = new ArrayList<TestStrip>();
		for (int i = 0; i < nTestStrips; i++) {
			testStrips.add(new TestStrip(i));
		}
		return testStrips;
	}
	
	public static void main(String[] args) {
		int nBottles = 1000;
		int nTestStrips = 10;
		for (int poisoned = 0; poisoned < nBottles; poisoned++) {
			ArrayList<Bottle> bottles = createBottles(nBottles, poisoned);
			ArrayList<TestStrip> testStrips = createTestStrips(nTestStrips);
			int poisonedId = findPoisonedBottle(bottles, testStrips);
			System.out.println("Suspected Bottle: " + poisonedId);
			if (poisonedId != poisoned) {
				System.out.println("ERROR");
				break;
			}
		}
	}
}


================================================
FILE: Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/QuestionB.java
================================================
package Q6_10_Test_Strips;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;

public class QuestionB {
	public static ArrayList<Bottle> createBottles(int nBottles, int poisoned) {
		ArrayList<Bottle> bottles = new ArrayList<Bottle>();
		for (int i = 0; i < nBottles; i++) {
			bottles.add(new Bottle(i));
		}
		
		if (poisoned == -1) {
			Random random = new Random();
			poisoned = random.nextInt(nBottles);
		}
		bottles.get(poisoned).setAsPoisoned();
		
		System.out.println("Added poison to bottle " + poisoned);
		
		return bottles;
	}

	public static int findPoisonedBottle(ArrayList<Bottle> bottles, ArrayList<TestStrip> strips) {
		if (bottles.size() > 1000 || strips.size() < 10) return -1;
		
		int tests = 4; // three digits, plus one extra
		int nTestStrips = strips.size();
		
		/* Run tests. */
		for (int day = 0; day < tests; day++) {
			runTestSet(bottles, strips, day);
		}
		
		/* Get results. */
		HashSet<Integer> previousResults = new HashSet<Integer>();
		int[] digits = new int[tests];
		for (int day = 0; day < tests; day++) {
			int resultDay = day + TestStrip.DAYS_FOR_RESULT;
			digits[day] = getPositiveOnDay(strips, resultDay, previousResults);
			previousResults.add(digits[day]);
		}
		
		/* If day 1's results matched day 0's, update the digit. */
		if (digits[1] == -1) {
			digits[1] = digits[0];
		}
		
		/* If day 2 matched day 0 or day 1, check day 3. Day 3 is
		 * the same as day 2, but incremented by 1. */
		if (digits[2] == -1) { 
			if (digits[3] == -1) { /* Day 3 didn't give new result */
				/* Digit 2 equals digit 0 or digit 1. But, digit 2, when incremented also matches 
				 * digit 0 or digit 1. This means that digit 0 incremented matches digit 1, or the
				 * other way around. */
				digits[2] = ((digits[0] + 1) % nTestStrips) == digits[1] ? digits[0] : digits[1];  
			} else {
				digits[2] = (digits[3] - 1 + nTestStrips) % nTestStrips;
			}
		}
		
		return digits[0] * 100 + digits[1] * 10 + digits[2];
	}
	
	/* Run set of tests for this day. */
	public static void runTestSet(ArrayList<Bottle> bottles, ArrayList<TestStrip> strips, int day) {
		if (day > 3) return; // only works for 3 days (digits) + one extra

		for (Bottle bottle : bottles) {
			int index = getTestStripIndexForDay(bottle, day, strips.size());
			TestStrip testStrip = strips.get(index);
			testStrip.addDropOnDay(day, bottle);
		}
	}
	
	/* Get test strip index that should be used on this bottle on this day. */ 
	public static int getTestStripIndexForDay(Bottle bottle, int day, int nTestStrips) {
		int id = bottle.getId();
		switch (day) {
			case 0: return id /100;
			case 1: return (id % 100) / 10;
			case 2: return id % 10;
			case 3: return (id % 10 + 1) % nTestStrips;
			default: return -1;
		}
	}	
	
	/* Get results that are positive for a particular day, excluding prior results. */
	public static int getPositiveOnDay(ArrayList<TestStrip> testStrips, int day, HashSet<Integer> previousResults) {
		for (TestStrip testStrip : testStrips) {
			int id = testStrip.getId();
			if (testStrip.isPositiveOnDay(day) && !previousResults.contains(id)) {
				return testStrip.getId();
			}
		}
		return -1;
	}	
	
	public static ArrayList<TestStrip> createTestStrips(int nTestStrips) {
		ArrayList<TestStrip> testStrips = new ArrayList<TestStrip>();
		for (int i = 0; i < nTestStrips; i++) {
			testStrips.add(new TestStrip(i));
		}
		return testStrips;
	}
	
	public static void main(String[] args) {
		int nBottles = 1000;
		int nTestStrips = 10;
		for (int poisoned = 0; poisoned < nBottles; poisoned++) {
			ArrayList<Bottle> bottles = createBottles(nBottles, poisoned);
			ArrayList<TestStrip> testStrips = createTestStrips(nTestStrips);
			int poisonedId = findPoisonedBottle(bottles, testStrips);
			System.out.println("Suspected Bottle: " + poisonedId);
			if (poisonedId != poisoned) {
				System.out.println("ERROR");
				break;
			}
		}
	}
}


================================================
FILE: Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/QuestionC.java
================================================
package Q6_10_Test_Strips;

import java.util.ArrayList;
import java.util.Random;

public class QuestionC {
	public static ArrayList<Bottle> createBottles(int nBottles, int poisoned) {
		ArrayList<Bottle> bottles = new ArrayList<Bottle>();
		for (int i = 0; i < nBottles; i++) {
			bottles.add(new Bottle(i));
		}
		
		if (poisoned == -1) {
			Random random = new Random();
			poisoned = random.nextInt(nBottles);
		}
		bottles.get(poisoned).setAsPoisoned();
		
		System.out.println("Added poison to bottle " + poisoned);
		
		return bottles;
	}
	
	public static int findPoisonedBottle(ArrayList<Bottle> bottles, ArrayList<TestStrip> strips) {
		runTests(bottles, strips);
		ArrayList<Integer> positive = getPositiveOnDay(strips, 7);
		return setBits(positive);
	}	
	
	/* Add bottles to test strips */
	public static void runTests(ArrayList<Bottle> bottles, ArrayList<TestStrip> testStrips) {
		for (Bottle bottle : bottles) {
			int id = bottle.getId();
			int bitIndex = 0;
			while (id > 0) {
				if ((id & 1) == 1) {
					testStrips.get(bitIndex).addDropOnDay(0, bottle);
				}
				bitIndex++;
				id >>= 1;
			}
		}
	}
	
	/* Get test strips that are positive on a particular day. */
	public static ArrayList<Integer> getPositiveOnDay(ArrayList<TestStrip> testStrips, int day) {
		ArrayList<Integer> positive = new ArrayList<Integer>();
		for (TestStrip testStrip : testStrips) {
			int id = testStrip.getId();
			if (testStrip.isPositiveOnDay(day)) {
				positive.add(id);
			}
		}
		return positive;
	}
	
	/* Create number by setting bits with indices specified in positive. */
	public static int setBits(ArrayList<Integer> positive) {
		int id = 0;
		for (Integer bitIndex : positive) {
			id |= 1 << bitIndex;
		}
		return id;
	}
	
	public static ArrayList<TestStrip> createTestStrips(int nTestStrips) {
		ArrayList<TestStrip> testStrips = new ArrayList<TestStrip>();
		for (int i = 0; i < nTestStrips; i++) {
			testStrips.add(new TestStrip(i));
		}
		return testStrips;
	}
	
	public static void main(String[] args) {
		int nBottles = 1000;
		int nTestStrips = 10;
		for (int poisoned = 0; poisoned < nBottles; poisoned++) {
			ArrayList<Bottle> bottles = createBottles(nBottles, poisoned);
			ArrayList<TestStrip> testStrips = createTestStrips(nTestStrips);
			int poisonedId = findPoisonedBottle(bottles, testStrips);
			System.out.println("Suspected Bottle: " + poisonedId);
			if (poisonedId != poisoned) {
				System.out.println("ERROR");
				break;
			}
		}
	}
}


================================================
FILE: Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/TestStrip.java
================================================
package Q6_10_Test_Strips;

import java.util.ArrayList;

public class TestStrip {
	public static int DAYS_FOR_RESULT = 7; 
	private ArrayList<ArrayList<Bottle>> dropsByDay = new ArrayList<ArrayList<Bottle>>();
	private int id;
	
	public TestStrip(int id) {
		this.id = id;
	}
	
	public int getId() {
		return id;
	}
	
	/* Resize list of days/drops to be large enough. */
	private void sizeDropsForDay(int day) {
		while (dropsByDay.size() <= day) {
			dropsByDay.add(new ArrayList<Bottle>());
		}
	}
	
	/* Add drop from bottle on specific day. */
	public void addDropOnDay(int day, Bottle bottle) {
		sizeDropsForDay(day);
		ArrayList<Bottle> drops = dropsByDay.get(day);
		drops.add(bottle);
	}
	
	/* Checks if any of the bottles in the set are poisoned. */
	private boolean hasPoison(ArrayList<Bottle> bottles) {
		for (Bottle b : bottles) {
			if (b.isPoisoned()) {
				return true;
			}
		}
		return false;
	}
	
	/* Gets bottles that were used in the test DAYS_FOR_RESULT days ago. */ 
	public ArrayList<Bottle> getLastWeeksBottles(int day) {
		if (day < DAYS_FOR_RESULT) {
			return null;
		}
		return dropsByDay.get(day - DAYS_FOR_RESULT);
	}
	
	/* Checks if the test strip has had any poisoned bottles since before DAYS_FOR_RESULT */
	public boolean isPositiveOnDay(int day) {
		int testDay = day - DAYS_FOR_RESULT;
		if (testDay < 0 || testDay >= dropsByDay.size()) {
			return false;
		}
		for (int d = 0; d <= testDay; d++) {
			ArrayList<Bottle> bottles = dropsByDay.get(d);
			if (hasPoison(bottles)) {
				return true;
			}
		}
		return false;
	}
}


================================================
FILE: Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/BlackJackCard.java
================================================
package Q7_01_Deck_of_Cards;

public class BlackJackCard extends Card {
	public BlackJackCard(int c, Suit s) {
		super(c, s);
	}
	
	public int value() {
		if (isAce()) { // Ace
			return 1; 
		} else if (isFaceCard()) { // Face card
			return 10;
		} else { // Number card
			return faceValue;
		}
	}
	
	public int minValue() {
		if (isAce()) { // Ace
			return 1; 
		} else {
			return value();
		}
	}
	
	public int maxValue() {
		if (isAce()) { // Ace
			return 11; 
		} else {
			return value();
		}
	}
	
	public boolean isAce() { 
		return faceValue == 1;
	} 
	
	public boolean isFaceCard() {
		return faceValue >= 11 && faceValue <= 13;
	}
}


================================================
FILE: Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/BlackJackGameAutomator.java
================================================
package Q7_01_Deck_of_Cards;

import java.util.ArrayList;

public class BlackJackGameAutomator {
	private Deck<BlackJackCard> deck;
	private BlackJackHand[] hands;
	private static final int HIT_UNTIL = 16;
	
	public BlackJackGameAutomator(int numPlayers) {
		hands = new BlackJackHand[numPlayers];
		for (int i = 0; i < numPlayers; i++) {
			hands[i] = new BlackJackHand();
		}
	}
	
	public boolean dealInitial() {
		for (BlackJackHand hand : hands) {
			BlackJackCard card1 = deck.dealCard();
			BlackJackCard card2 = deck.dealCard();
			if (card1 == null || card2 == null) {
				return false;
			}
			hand.addCard(card1);
			hand.addCard(card2);	
		}
		return true;
	}
	
	public ArrayList<Integer> getBlackJacks() {
		ArrayList<Integer> winners = new ArrayList<Integer>();
		for (int i = 0; i < hands.length; i++) {
			if (hands[i].isBlackJack()) {
				winners.add(i);
			}
		}
		return winners;
	}
	
	public boolean playHand(int i) {
		BlackJackHand hand = hands[i];
		return playHand(hand);
	}
	
	public boolean playHand(BlackJackHand hand) {
		while (hand.score() < HIT_UNTIL) {
			BlackJackCard card = deck.dealCard();
			if (card == null) {
				return false;
			}
			hand.addCard(card);
		}
		return true;
	}	
	
	public boolean playAllHands() {
		for (BlackJackHand hand : hands) {
			if (!playHand(hand)) {
				return false;
			}
		}
		return true;
	}
	
	public ArrayList<Integer> getWinners() {
		ArrayList<Integer> winners = new ArrayList<Integer>();
		int winningScore = 0;
		for (int i = 0; i < hands.length; i++) {
			BlackJackHand hand = hands[i];
			if (!hand.busted()) {
				if (hand.score() > winningScore) {
					winningScore = hand.score();
					winners.clear();
					winners.add(i);
				} else if (hand.score() == winningScore) {
					winners.add(i);
				}
			}
		}
		return winners;
	}
	
	public void initializeDeck() {
		ArrayList<BlackJackCard> cards = new ArrayList<BlackJackCard>();
		for (int i = 1; i <= 13; i++) {
			for (int j = 0; j <= 3; j++) {
				Suit suit = Suit.getSuitFromValue(j);
				BlackJackCard card = new BlackJackCard(i, suit);
				cards.add(card);
			}
		}
		
		deck = new Deck<BlackJackCard>();
		deck.setDeckOfCards(cards);
		deck.shuffle();	
	}
	
	public void printHandsAndScore() {
		for (int i = 0; i < hands.length; i++) {
			System.out.print("Hand " + i + " (" + hands[i].score() + "): ");
			hands[i].print();
			System.out.println("");
		}
	}
}


================================================
FILE: Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/BlackJackHand.java
================================================
package Q7_01_Deck_of_Cards;

import java.util.ArrayList;

public class BlackJackHand extends Hand<BlackJackCard> {
	public BlackJackHand() {
		
	}
	
	public int score() {
		ArrayList<Integer> scores = possibleScores();
		int maxUnder = Integer.MIN_VALUE;
		int minOver = Integer.MAX_VALUE;
		for (int score : scores) {
			if (score > 21 && score < minOver) {
				minOver = score;
			} else if (score <= 21 && score > maxUnder) {
				maxUnder = score;
			}
		}
		return maxUnder == Integer.MIN_VALUE ? m
Download .txt
gitextract_k4kr__1r/

├── .classpath
├── .gitignore
├── .gitmodules
├── .project
├── Java/
│   ├── Big O/
│   │   ├── Example_16/
│   │   │   └── Example.java
│   │   └── QVI_11_Print_Sorted_Strings/
│   │       └── Question.java
│   ├── Ch 01. Arrays and Strings/
│   │   ├── Q1_01_Is_Unique/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q1_02_Check_Permutation/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q1_03_URLify/
│   │   │   └── Question.java
│   │   ├── Q1_04_Palindrome_Permutation/
│   │   │   ├── Common.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q1_05_One_Away/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q1_06_String_Compression/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q1_07_Rotate_Matrix/
│   │   │   └── Question.java
│   │   ├── Q1_08_Zero_Matrix/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   └── Q1_09_String_Rotation/
│   │       └── Question.java
│   ├── Ch 02. Linked Lists/
│   │   ├── Q2_01_Remove_Dups/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q2_02_Return_Kth_To_Last/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.cpp
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q2_03_Delete_Middle_Node/
│   │   │   └── Question.java
│   │   ├── Q2_04_Partition/
│   │   │   ├── Question.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q2_05_Sum_Lists/
│   │   │   ├── PartialSum.java
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q2_06_Palindrome/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q2_07_Intersection/
│   │   │   └── Question.java
│   │   └── Q2_08_Loop_Detection/
│   │       └── Question.java
│   ├── Ch 03. Stacks and Queues/
│   │   ├── Introduction/
│   │   │   ├── MyQueue.java
│   │   │   ├── MyStack.java
│   │   │   ├── QueueTester.java
│   │   │   └── StackTester.java
│   │   ├── Q3_01_Three_in_One/
│   │   │   ├── FixedMultiStack.java
│   │   │   ├── FullStackException.java
│   │   │   ├── MultiStack.java
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q3_02_Stack_Min/
│   │   │   ├── NodeWithMin.java
│   │   │   ├── Question.java
│   │   │   ├── StackWithMin.java
│   │   │   └── StackWithMin2.java
│   │   ├── Q3_03_Stack_of_Plates/
│   │   │   ├── Node.java
│   │   │   ├── Question.java
│   │   │   ├── SetOfStacks.java
│   │   │   └── Stack.java
│   │   ├── Q3_04_Queue_via_Stacks/
│   │   │   ├── MyQueue.java
│   │   │   └── Question.java
│   │   ├── Q3_05_Sort_Stack/
│   │   │   └── Question.java
│   │   └── Q3_06_Animal_Shelter/
│   │       ├── Animal.java
│   │       ├── AnimalQueue.java
│   │       ├── Cat.java
│   │       ├── Dog.java
│   │       └── Question.java
│   ├── Ch 04. Trees and Graphs/
│   │   ├── Introduction/
│   │   │   └── Traversals.java
│   │   ├── Q4_01_Route_Between_Nodes/
│   │   │   ├── Graph.java
│   │   │   ├── Node.java
│   │   │   └── Question.java
│   │   ├── Q4_02_Minimal_Tree/
│   │   │   └── Question.java
│   │   ├── Q4_03_List_of_Depths/
│   │   │   ├── QuestionBFS.java
│   │   │   └── QuestionDFS.java
│   │   ├── Q4_04_Check_Balanced/
│   │   │   ├── QuestionBrute.java
│   │   │   └── QuestionImproved.java
│   │   ├── Q4_05_Validate_BST/
│   │   │   ├── IntWrapper.java
│   │   │   ├── Question.java
│   │   │   └── QuestionB.java
│   │   ├── Q4_06_Successor/
│   │   │   └── Question.java
│   │   ├── Q4_07_Build_Order/
│   │   │   ├── DFS/
│   │   │   │   ├── Graph.java
│   │   │   │   ├── Project.java
│   │   │   │   └── Question.java
│   │   │   └── EdgeRemoval/
│   │   │       ├── Graph.java
│   │   │       ├── Project.java
│   │   │       └── Question.java
│   │   ├── Q4_08_First_Common_Ancestor/
│   │   │   ├── Question.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   ├── QuestionE.java
│   │   │   ├── QuestionEBad.java
│   │   │   ├── QuestionF.java
│   │   │   └── Tester.java
│   │   ├── Q4_09_BST_Sequences/
│   │   │   └── Question.java
│   │   ├── Q4_10_Check_Subtree/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q4_11_Random_Node/
│   │   │   ├── Question.java
│   │   │   ├── Tree.java
│   │   │   └── TreeNode.java
│   │   └── Q4_12_Paths_with_Sum/
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       └── Tester.java
│   ├── Ch 05. Bit Manipulation/
│   │   ├── Q5_01_Insertion/
│   │   │   └── Question.java
│   │   ├── Q5_02_Binary_to_String/
│   │   │   └── Question.java
│   │   ├── Q5_03_Flip_Bit_to_Win/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q5_04_Next_Number/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q5_06_Conversion/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q5_07_Pairwise_Swap/
│   │   │   └── Question.java
│   │   ├── Q5_08_Draw_Line/
│   │   │   └── Question.java
│   │   └── Sample_Code/
│   │       ├── RightShifts.java
│   │       └── Sample_Code.java
│   ├── Ch 06. Math and Logic Puzzles/
│   │   ├── Introduction/
│   │   │   ├── PrimeNumbers.java
│   │   │   └── SieveOfEratosthenes.java
│   │   ├── Q6_05_Egg_Drop/
│   │   │   └── Question.java
│   │   ├── Q6_07_The_Apocalypse/
│   │   │   └── Question.java
│   │   └── Q6_10_Test_Strips/
│   │       ├── Bottle.java
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       ├── QuestionC.java
│   │       └── TestStrip.java
│   ├── Ch 07. Object-Oriented Design/
│   │   ├── Q7_01_Deck_of_Cards/
│   │   │   ├── BlackJackCard.java
│   │   │   ├── BlackJackGameAutomator.java
│   │   │   ├── BlackJackHand.java
│   │   │   ├── Card.java
│   │   │   ├── Deck.java
│   │   │   ├── Hand.java
│   │   │   ├── Question.java
│   │   │   └── Suit.java
│   │   ├── Q7_02_Call_Center/
│   │   │   ├── Call.java
│   │   │   ├── CallHandler.java
│   │   │   ├── Caller.java
│   │   │   ├── Director.java
│   │   │   ├── Employee.java
│   │   │   ├── Manager.java
│   │   │   ├── Rank.java
│   │   │   ├── Respondent.java
│   │   │   └── Test.java
│   │   ├── Q7_03_Jukebox/
│   │   │   ├── CD.java
│   │   │   ├── CDPlayer.java
│   │   │   ├── JukeBox.java
│   │   │   ├── Playlist.java
│   │   │   ├── Song.java
│   │   │   ├── SongSelector.java
│   │   │   └── User.java
│   │   ├── Q7_04_Parking_Lot/
│   │   │   ├── Bus.java
│   │   │   ├── Car.java
│   │   │   ├── Level.java
│   │   │   ├── Motorcycle.java
│   │   │   ├── ParkingLot.java
│   │   │   ├── ParkingSpot.java
│   │   │   ├── Question.java
│   │   │   ├── Vehicle.java
│   │   │   └── VehicleSize.java
│   │   ├── Q7_05_Online_Book_Reader/
│   │   │   ├── Book.java
│   │   │   ├── Display.java
│   │   │   ├── Library.java
│   │   │   ├── OnlineReaderSystem.java
│   │   │   ├── User.java
│   │   │   └── UserManager.java
│   │   ├── Q7_06_Jigsaw/
│   │   │   ├── Edge.java
│   │   │   ├── Orientation.java
│   │   │   ├── Piece.java
│   │   │   ├── Puzzle.java
│   │   │   ├── Question.java
│   │   │   └── Shape.java
│   │   ├── Q7_07_Chat_Server/
│   │   │   ├── AddRequest.java
│   │   │   ├── Conversation.java
│   │   │   ├── GroupChat.java
│   │   │   ├── Message.java
│   │   │   ├── PrivateChat.java
│   │   │   ├── RequestStatus.java
│   │   │   ├── System.java
│   │   │   ├── User.java
│   │   │   ├── UserManager.java
│   │   │   ├── UserStatus.java
│   │   │   └── UserStatusType.java
│   │   ├── Q7_08_Othello/
│   │   │   ├── Automator.java
│   │   │   ├── Board.java
│   │   │   ├── Color.java
│   │   │   ├── Direction.java
│   │   │   ├── Game.java
│   │   │   ├── Location.java
│   │   │   ├── Piece.java
│   │   │   ├── Player.java
│   │   │   └── Question.java
│   │   ├── Q7_09_Circular_Array/
│   │   │   ├── CircularArray.java
│   │   │   └── Question.java
│   │   ├── Q7_10_Minesweeper/
│   │   │   ├── Board.java
│   │   │   ├── Cell.java
│   │   │   ├── Game.java
│   │   │   ├── Question.java
│   │   │   ├── UserPlay.java
│   │   │   └── UserPlayResult.java
│   │   ├── Q7_11_File_System/
│   │   │   ├── Directory.java
│   │   │   ├── Entry.java
│   │   │   ├── File.java
│   │   │   └── Question.java
│   │   └── Q7_12_Hash_Table/
│   │       ├── Dummy.java
│   │       ├── Hasher.java
│   │       └── Question.java
│   ├── Ch 08. Recursion and Dynamic Programming/
│   │   ├── Introduction/
│   │   │   ├── FibonacciA.java
│   │   │   ├── FibonacciB.java
│   │   │   ├── FibonacciC.java
│   │   │   └── FibonacciD.java
│   │   ├── Q8_01_Triple_Step/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q8_02_Robot_in_a_Grid/
│   │   │   ├── Point.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q8_03_Magic_Index/
│   │   │   ├── Question.java
│   │   │   └── QuestionB.java
│   │   ├── Q8_04_Power_Set/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q8_05_Recursive_Multiply/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q8_06_Towers_of_Hanoi/
│   │   │   ├── Question.java
│   │   │   └── Tower.java
│   │   ├── Q8_07_Permutations_Without_Dups/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── QuestionC.java
│   │   ├── Q8_08_Permutations_With_Dups/
│   │   │   └── Question.java
│   │   ├── Q8_09_Parens/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q8_10_Paint_Fill/
│   │   │   └── Question.java
│   │   ├── Q8_11_Coins/
│   │   │   ├── Question.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q8_12_Eight_Queens/
│   │   │   └── Question.java
│   │   ├── Q8_13_Stack_of_Boxes/
│   │   │   ├── Box.java
│   │   │   ├── BoxComparator.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   └── Q8_14_Boolean_Evaluation/
│   │       ├── Others.java
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       ├── QuestionC.java
│   │       └── Tester.java
│   ├── Ch 09. Scalability and Memory Limits/
│   │   ├── Q9_02_Social_Network/
│   │   │   ├── BFSData.java
│   │   │   ├── Machine.java
│   │   │   ├── PathNode.java
│   │   │   ├── Person.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── Server.java
│   │   │   └── Tester.java
│   │   └── Q9_05_Cache/
│   │       ├── Cache.java
│   │       ├── Node.java
│   │       └── Question.java
│   ├── Ch 10. Sorting and Searching/
│   │   ├── Introduction/
│   │   │   ├── BinarySearch.java
│   │   │   ├── MergeSort.java
│   │   │   └── Quicksort.java
│   │   ├── Q10_01_Sorted_Merge/
│   │   │   └── Question.java
│   │   ├── Q10_02_Group_Anagrams/
│   │   │   ├── AnagramComparator.java
│   │   │   ├── Question.java
│   │   │   └── QuestionB.java
│   │   ├── Q10_03_Search_in_Rotated_Array/
│   │   │   └── Question.java
│   │   ├── Q10_04_Sorted_Search_No_Size/
│   │   │   └── Arrayish/
│   │   │       ├── Listy.java
│   │   │       └── Question.java
│   │   ├── Q10_05_Sparse_Search/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q10_07_Missing_Int/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── input.txt
│   │   ├── Q10_08_Find_Duplicates/
│   │   │   ├── BitSet.java
│   │   │   └── Question.java
│   │   ├── Q10_09_Sorted_Matrix_Search/
│   │   │   ├── Coordinate.java
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q10_10_Rank_from_Stream/
│   │   │   ├── IntComparable.java
│   │   │   ├── Question.java
│   │   │   └── RankNode.java
│   │   └── Q10_11_Peaks_and_Valleys/
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       ├── QuestionC.java
│   │       └── Tester.java
│   ├── Ch 13. Java/
│   │   ├── Introduction/
│   │   │   ├── Ambiguous.java
│   │   │   ├── Circle.java
│   │   │   ├── Introduction.java
│   │   │   ├── IntroductionCollections.java
│   │   │   ├── IntroductionOverriding.java
│   │   │   ├── Shape.java
│   │   │   └── Square.java
│   │   ├── Q13_01_Private_Constructor/
│   │   │   └── Question.java
│   │   ├── Q13_05_TreeMap_HashMap_LinkedHashMap/
│   │   │   └── Question.java
│   │   ├── Q13_06_Object_Reflection/
│   │   │   ├── Question.java
│   │   │   └── Rectangle.java
│   │   ├── Q13_07_Lambda_Expressions/
│   │   │   ├── Country.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   └── Q13_08_Lambda_Random/
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       └── QuestionC.java
│   ├── Ch 15. Threads and Locks/
│   │   ├── IntroductionA/
│   │   │   ├── ExampleA.java
│   │   │   └── RunnableThreadExample.java
│   │   ├── IntroductionB/
│   │   │   ├── ExampleB.java
│   │   │   └── ThreadExample.java
│   │   ├── IntroductionLocks/
│   │   │   ├── Intro.java
│   │   │   ├── LockedATM.java
│   │   │   ├── MyClass.java
│   │   │   └── NoLockATM.java
│   │   ├── IntroductionSynchronization/
│   │   │   ├── Intro.java
│   │   │   ├── MyClass.java
│   │   │   └── MyObject.java
│   │   ├── IntroductionSynchronizedBlocks/
│   │   │   ├── Intro.java
│   │   │   ├── MyClass.java
│   │   │   └── MyObject.java
│   │   ├── IntroductionWaitNotify/
│   │   │   ├── Intro.java
│   │   │   ├── MyClass.java
│   │   │   └── MyObject.java
│   │   ├── Q15_03_Dining_Philosophers/
│   │   │   ├── QuestionA/
│   │   │   │   ├── Chopstick.java
│   │   │   │   ├── Philosopher.java
│   │   │   │   └── Question.java
│   │   │   └── QuestionB/
│   │   │       ├── Chopstick.java
│   │   │       ├── Philosopher.java
│   │   │       └── Question.java
│   │   ├── Q15_04_Deadlock_Free_Class/
│   │   │   ├── LockFactory.java
│   │   │   ├── LockNode.java
│   │   │   └── Question.java
│   │   ├── Q15_05_Call_In_Order/
│   │   │   ├── Foo.java
│   │   │   ├── FooBad.java
│   │   │   ├── MyThread.java
│   │   │   └── Question.java
│   │   ├── Q15_06_Synchronized_Methods/
│   │   │   ├── Foo.java
│   │   │   ├── MyThread.java
│   │   │   └── Question.java
│   │   └── Q15_07_FizzBuzz/
│   │       ├── FBThread.java
│   │       ├── FizzBuzzThread.java
│   │       ├── NumberThread.java
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       └── QuestionC.java
│   ├── Ch 16. Moderate/
│   │   ├── Q16_01_Number_Swapper/
│   │   │   └── Question.java
│   │   ├── Q16_02_Word_Frequencies/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q16_03_Intersection/
│   │   │   ├── Line.java
│   │   │   ├── Point.java
│   │   │   ├── Question.java
│   │   │   └── Tester.java
│   │   ├── Q16_04_Tic_Tac_Win/
│   │   │   ├── Piece.java
│   │   │   ├── Position.java
│   │   │   ├── PositionIterator.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   ├── QuestionE.java
│   │   │   ├── QuestionF.java
│   │   │   ├── QuestionG.java
│   │   │   ├── QuestionH.java
│   │   │   └── Tester.java
│   │   ├── Q16_05_Factorial_Zeros/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q16_06_Smallest_Difference/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q16_07_Number_Max/
│   │   │   └── Question.java
│   │   ├── Q16_08_English_Int/
│   │   │   └── Question.java
│   │   ├── Q16_09_Operations/
│   │   │   └── Question.java
│   │   ├── Q16_10_Living_People/
│   │   │   ├── Person.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q16_11_Diving_Board/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q16_12_XML_Encoding/
│   │   │   ├── Attribute.java
│   │   │   ├── Element.java
│   │   │   ├── QuestionOO.java
│   │   │   └── QuestionString.java
│   │   ├── Q16_13_Bisect_Squares/
│   │   │   ├── Line.java
│   │   │   ├── Point.java
│   │   │   ├── Question.java
│   │   │   ├── Square Cut Tester - Q16_13.xlsx
│   │   │   └── Square.java
│   │   ├── Q16_14_Best_Line/
│   │   │   ├── GraphPoint.java
│   │   │   ├── Line.java
│   │   │   └── Question.java
│   │   ├── Q16_15_Master_Mind/
│   │   │   ├── Question.java
│   │   │   ├── Result.java
│   │   │   └── Tester.java
│   │   ├── Q16_16_Sub_Sort/
│   │   │   ├── Question.java
│   │   │   ├── QuestionB.java
│   │   │   ├── Range.java
│   │   │   └── Tester.java
│   │   ├── Q16_17_Contiguous_Sequence/
│   │   │   └── Question.java
│   │   ├── Q16_18_Pattern_Matcher/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q16_19_Pond_Sizes/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q16_20_T9/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── QuestionC.java
│   │   ├── Q16_21_Sum_Swap/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q16_22_Langtons_Ant/
│   │   │   ├── Ant.java
│   │   │   ├── Board.java
│   │   │   ├── Grid.java
│   │   │   ├── Orientation.java
│   │   │   ├── Position.java
│   │   │   └── Question.java
│   │   ├── Q16_23_Rand7_From_Rand5/
│   │   │   ├── Question.java
│   │   │   └── QuestionB.java
│   │   ├── Q16_24_Pairs_With_Sum/
│   │   │   ├── Pair.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q16_25_LRU_Cache/
│   │   │   ├── Cache.java
│   │   │   └── Question.java
│   │   └── Q16_26_Calculator/
│   │       ├── Operator.java
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       └── Term.java
│   ├── Ch 17. Hard/
│   │   ├── Q17_01_Add_Without_Plus/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q17_02_Shuffle/
│   │   │   └── Question.java
│   │   ├── Q17_03_Random_Set/
│   │   │   ├── Question.java
│   │   │   └── QuestionAlternate.java
│   │   ├── Q17_04_Missing_Number/
│   │   │   ├── BitInteger.java
│   │   │   └── Question.java
│   │   ├── Q17_05_Letters_and_Numbers/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q17_06_Count_of_2s/
│   │   │   ├── Question.java
│   │   │   └── QuestionBrute.java
│   │   ├── Q17_07_Baby_Names/
│   │   │   ├── Graph.java
│   │   │   ├── GraphNode.java
│   │   │   ├── NameSet.java
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q17_08_Circus_Tower/
│   │   │   ├── HtWt.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionOld.java
│   │   │   └── Tester.java
│   │   ├── Q17_09_Kth_Multiple/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── QuestionC.java
│   │   ├── Q17_10_Majority_Element/
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q17_11_Word_Distance/
│   │   │   ├── LocationPair.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── Tester.java
│   │   ├── Q17_12_BiNode/
│   │   │   ├── BiNode.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── QuestionC.java
│   │   ├── Q17_13_ReSpace/
│   │   │   ├── ParseResult.java
│   │   │   ├── QuestionA.java
│   │   │   └── QuestionB.java
│   │   ├── Q17_14_Smallest_K/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q17_15_Longest_Word/
│   │   │   ├── LengthComparator.java
│   │   │   └── Question.java
│   │   ├── Q17_16_The_Masseuse/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   └── Tester.java
│   │   ├── Q17_17_Multi_Search/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── Trie.java
│   │   │   └── TrieNode.java
│   │   ├── Q17_18_Shortest_Supersequence/
│   │   │   ├── HeapNode.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── QuestionD.java
│   │   │   ├── QuestionE.java
│   │   │   ├── Range.java
│   │   │   └── Tester.java
│   │   ├── Q17_19_Missing_Two/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   └── QuestionC.java
│   │   ├── Q17_20_Continuous_Median/
│   │   │   ├── MaxHeapComparator.java
│   │   │   ├── MinHeapComparator.java
│   │   │   └── Question.java
│   │   ├── Q17_21_Volume_of_Histogram/
│   │   │   ├── HistogramData.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q17_22_Word_Transformer/
│   │   │   ├── BFSData.java
│   │   │   ├── PathNode.java
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   └── Tester.java
│   │   ├── Q17_23_Max_Black_Square/
│   │   │   ├── Question.java
│   │   │   ├── QuestionEff.java
│   │   │   ├── SquareCell.java
│   │   │   └── Subsquare.java
│   │   ├── Q17_24_Max_Submatrix/
│   │   │   ├── QuestionA.java
│   │   │   ├── QuestionB.java
│   │   │   ├── QuestionC.java
│   │   │   ├── Range.java
│   │   │   ├── SubMatrix.java
│   │   │   └── Tester.java
│   │   ├── Q17_25_Word_Rectangle/
│   │   │   ├── Question.java
│   │   │   ├── Rectangle.java
│   │   │   └── WordGroup.java
│   │   └── Q17_26_Sparse_Similarity/
│   │       ├── DocPair.java
│   │       ├── Document.java
│   │       ├── QuestionA.java
│   │       ├── QuestionB.java
│   │       ├── QuestionC.java
│   │       └── Tester.java
│   ├── CtCILibrary/
│   │   └── CtCILibrary/
│   │       ├── AssortedMethods.java
│   │       ├── BTreePrinter.java
│   │       ├── BitVector.java
│   │       ├── HashMapList.java
│   │       ├── LinkedListNode.java
│   │       ├── TreeNode.java
│   │       ├── Trie.java
│   │       └── TrieNode.java
│   └── Introduction/
│       ├── Big_O/
│       │   ├── Ex_01.java
│       │   ├── Ex_02.java
│       │   ├── Ex_03.java
│       │   ├── Ex_04.java
│       │   ├── Ex_05.java
│       │   ├── Ex_06.java
│       │   ├── Ex_07.java
│       │   ├── Ex_08.java
│       │   ├── Ex_09.java
│       │   ├── Ex_10.java
│       │   ├── Ex_11.java
│       │   ├── Ex_14.java
│       │   ├── Ex_15.java
│       │   ├── Ex_16.java
│       │   ├── Ex_17.java
│       │   ├── Ex_18.java
│       │   ├── Ex_19.java
│       │   ├── Ex_20.java
│       │   ├── Q_01.java
│       │   ├── Q_02.java
│       │   ├── Q_03.java
│       │   ├── Q_04.java
│       │   ├── Q_05.java
│       │   ├── Q_06.java
│       │   ├── Q_09.java
│       │   ├── Q_10.java
│       │   ├── Q_11.java
│       │   └── Q_12.java
│       ├── CompareBinaryToHex/
│       │   └── CompareBinaryToHex.java
│       └── SwapMinMax/
│           └── SwapMinMax.java
└── README.md
Download .txt
Showing preview only (240K chars total). Download the full file or copy to clipboard to get everything.
SYMBOL INDEX (2741 symbols across 585 files)

FILE: Java/Big O/Example_16/Example.java
  class Example (line 3) | public class Example {
    method powersOf2 (line 5) | public static int powersOf2(int n) {
    method main (line 19) | public static void main(String[] args) {

FILE: Java/Big O/QVI_11_Print_Sorted_Strings/Question.java
  class Question (line 4) | public class Question {
    method printSortedStrings (line 8) | public static void printSortedStrings(int remaining) {
    method printSortedStrings (line 12) | public static void printSortedStrings(int remaining, String prefix) {
    method isInOrder (line 25) | public static boolean isInOrder(String s) {
    method ithLetter (line 37) | public static char ithLetter(int i) {
    method main (line 41) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_01_Is_Unique/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method isUniqueChars (line 4) | public static boolean isUniqueChars(String str) {
    method main (line 17) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_01_Is_Unique/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method isUniqueChars (line 6) | public static boolean isUniqueChars(String str) {
    method main (line 19) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_01_Is_Unique/Tester.java
  class Tester (line 3) | public class Tester {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_02_Check_Permutation/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method sort (line 4) | public static String sort(String s) {
    method permutation (line 10) | public static boolean permutation(String s, String t) {
    method main (line 14) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_02_Check_Permutation/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method permutation (line 4) | public static boolean permutation(String s, String t) {
    method main (line 22) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_03_URLify/Question.java
  class Question (line 5) | public class Question {
    method replaceSpaces (line 7) | public static void replaceSpaces(char[] str, int trueLength) {
    method findLastCharacter (line 29) | public static int findLastCharacter(char[] str) {
    method main (line 38) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/Common.java
  class Common (line 3) | public class Common {
    method getCharNumber (line 5) | public static int getCharNumber(Character c) {
    method buildCharFrequencyTable (line 16) | public static int[] buildCharFrequencyTable(String phrase) {

FILE: Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method checkMaxOneOdd (line 4) | public static boolean checkMaxOneOdd(int[] table) {
    method isPermutationOfPalindrome (line 17) | public static boolean isPermutationOfPalindrome(String phrase) {
    method main (line 22) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method isPermutationOfPalindrome (line 5) | public static boolean isPermutationOfPalindrome(String phrase) {
    method main (line 23) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/QuestionC.java
  class QuestionC (line 3) | public class QuestionC {
    method toggle (line 5) | public static int toggle(int bitVector, int index) {
    method createBitVector (line 19) | public static int createBitVector(String phrase) {
    method checkAtMostOneBitSet (line 30) | public static boolean checkAtMostOneBitSet(int bitVector) {
    method isPermutationOfPalindrome (line 34) | public static boolean isPermutationOfPalindrome(String phrase) {
    method main (line 39) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/Tester.java
  class Tester (line 3) | public class Tester {
    method main (line 6) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method oneEditReplace (line 5) | public static boolean oneEditReplace(String s1, String s2) {
    method oneEditInsert (line 20) | public static boolean oneEditInsert(String s1, String s2) {
    method oneEditAway (line 37) | public static boolean oneEditAway(String first, String second) {
    method main (line 48) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method oneEditAway (line 4) | public static boolean oneEditAway(String first, String second) {
    method main (line 35) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_05_One_Away/Tester.java
  class Tester (line 3) | public class Tester {
    method test (line 5) | public static void test(String a, String b, boolean expected) {
    method main (line 16) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_06_String_Compression/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method compressBad (line 4) | public static String compressBad(String str) {
    method main (line 19) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_06_String_Compression/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method compress (line 4) | public static String compress(String str) {
    method main (line 20) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_06_String_Compression/QuestionC.java
  class QuestionC (line 3) | public class QuestionC {
    method compress (line 4) | public static String compress(String str) {
    method countCompression (line 23) | public static int countCompression(String str) {
    method main (line 38) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_06_String_Compression/Tester.java
  class Tester (line 3) | public class Tester {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_07_Rotate_Matrix/Question.java
  class Question (line 5) | public class Question {
    method rotate (line 7) | public static boolean rotate(int[][] matrix) {
    method main (line 34) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_08_Zero_Matrix/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method nullifyRow (line 6) | public static void nullifyRow(int[][] matrix, int row) {
    method nullifyColumn (line 12) | public static void nullifyColumn(int[][] matrix, int col) {
    method setZeros (line 18) | public static void setZeros(int[][] matrix) {
    method matricesAreEqual (line 47) | public static boolean matricesAreEqual(int[][] m1, int[][] m2) {
    method cloneMatrix (line 62) | public static int[][] cloneMatrix(int[][] matrix) {
    method main (line 72) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_08_Zero_Matrix/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method nullifyRow (line 6) | public static void nullifyRow(int[][] matrix, int row) {
    method nullifyColumn (line 12) | public static void nullifyColumn(int[][] matrix, int col) {
    method setZeros (line 18) | public static void setZeros(int[][] matrix) {
    method matricesAreEqual (line 73) | public static boolean matricesAreEqual(int[][] m1, int[][] m2) {
    method cloneMatrix (line 88) | public static int[][] cloneMatrix(int[][] matrix) {
    method main (line 98) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_08_Zero_Matrix/Tester.java
  class Tester (line 5) | public class Tester {
    method matricesAreEqual (line 6) | public static boolean matricesAreEqual(int[][] m1, int[][] m2) {
    method cloneMatrix (line 21) | public static int[][] cloneMatrix(int[][] matrix) {
    method main (line 31) | public static void main(String[] args) {

FILE: Java/Ch 01. Arrays and Strings/Q1_09_String_Rotation/Question.java
  class Question (line 3) | public class Question {
    method isSubstring (line 4) | public static boolean isSubstring(String big, String small) {
    method isRotation (line 12) | public static boolean isRotation(String s1, String s2) {
    method main (line 23) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_01_Remove_Dups/QuestionA.java
  class QuestionA (line 6) | public class QuestionA {
    method deleteDups (line 7) | public static void deleteDups(LinkedListNode n) {
    method main (line 21) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_01_Remove_Dups/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method deleteDups (line 6) | public static void deleteDups(LinkedListNode head) {
    method main (line 22) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_01_Remove_Dups/QuestionC.java
  class QuestionC (line 5) | public class QuestionC {
    method deleteDups (line 6) | public static void deleteDups(LinkedListNode head) {
    method main (line 39) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_01_Remove_Dups/Tester.java
  class Tester (line 5) | public class Tester {
    method main (line 7) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method printKthToLast (line 7) | public static int printKthToLast(LinkedListNode head, int k) {
    method main (line 18) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/QuestionB.cpp
  type node (line 4) | struct node {
  function node (line 9) | node* nthToLast(node* head, int k, int& i) {
  function node (line 21) | node* nthToLast(node* head, int k) {
  function node (line 26) | node* createList(int count) {
  function printList (line 39) | void printList(node* head) {
  function main (line 46) | int main() {

FILE: Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/QuestionC.java
  class QuestionC (line 5) | public class QuestionC {
    class Index (line 6) | public static class Index {
    method kthToLast (line 10) | public static LinkedListNode kthToLast(LinkedListNode head, int k) {
    method kthToLast (line 15) | public static LinkedListNode kthToLast(LinkedListNode head, int k, Ind...
    method main (line 27) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/QuestionD.java
  class QuestionD (line 5) | public class QuestionD {
    method nthToLast (line 7) | public static LinkedListNode nthToLast(LinkedListNode head, int k) {
    method main (line 26) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/Tester.java
  class Tester (line 5) | public class Tester {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_03_Delete_Middle_Node/Question.java
  class Question (line 6) | public class Question {
    method deleteNode (line 8) | public static boolean deleteNode(LinkedListNode n) {
    method main (line 18) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_04_Partition/Question.java
  class Question (line 5) | public class Question {
    method partition (line 7) | public static LinkedListNode partition(LinkedListNode node, int x) {
    method main (line 46) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_04_Partition/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method partition (line 7) | public static LinkedListNode partition(LinkedListNode node, int x) {
    method main (line 39) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_04_Partition/QuestionC.java
  class QuestionC (line 5) | public class QuestionC {
    method partition (line 7) | public static LinkedListNode partition(LinkedListNode node, int x) {
    method main (line 30) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_04_Partition/Tester.java
  class Tester (line 5) | public class Tester {
    method createLinkedList (line 7) | public static LinkedListNode createLinkedList() {
    method main (line 18) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_05_Sum_Lists/PartialSum.java
  class PartialSum (line 5) | public class PartialSum {

FILE: Java/Ch 02. Linked Lists/Q2_05_Sum_Lists/QuestionA.java
  class QuestionA (line 6) | public class QuestionA {
    method addLists (line 7) | private static LinkedListNode addLists(LinkedListNode l1, LinkedListNo...
    method addLists (line 11) | private static LinkedListNode addLists(LinkedListNode l1, LinkedListNo...
    method linkedListToInt (line 34) | public static int linkedListToInt(LinkedListNode node) {
    method main (line 42) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_05_Sum_Lists/QuestionB.java
  class QuestionB (line 4) | public class QuestionB {
    method length (line 5) | private static int length(LinkedListNode l) {
    method addListsHelper (line 13) | private static PartialSum addListsHelper(LinkedListNode l1, LinkedList...
    method addLists (line 26) | private static LinkedListNode addLists(LinkedListNode l1, LinkedListNo...
    method padList (line 43) | private static LinkedListNode padList(LinkedListNode l, int padding) {
    method insertBefore (line 51) | private static LinkedListNode insertBefore(LinkedListNode list, int da...
    method linkedListToInt (line 59) | public static int linkedListToInt(LinkedListNode node) {
    method main (line 68) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_06_Palindrome/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method isPalindrome (line 6) | public static boolean isPalindrome(LinkedListNode head) {
    method reverseAndClone (line 11) | public static LinkedListNode reverseAndClone(LinkedListNode node) {
    method isEqual (line 22) | public static boolean isEqual(LinkedListNode one, LinkedListNode two) {
    method main (line 33) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_06_Palindrome/QuestionB.java
  class QuestionB (line 7) | public class QuestionB {
    method isPalindrome (line 8) | public static boolean isPalindrome(LinkedListNode head) {
    method main (line 35) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_06_Palindrome/QuestionC.java
  class QuestionC (line 5) | public class QuestionC {
    class Result (line 6) | public static class Result {
      method Result (line 9) | public Result(LinkedListNode n, boolean res) {
    method isPalindromeRecurse (line 15) | public static Result isPalindromeRecurse(LinkedListNode head, int leng...
    method lengthOfList (line 40) | public static int lengthOfList(LinkedListNode n) {
    method isPalindrome (line 49) | public static boolean isPalindrome(LinkedListNode head) {
    method main (line 55) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_06_Palindrome/Tester.java
  class Tester (line 5) | public class Tester {
    method main (line 7) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_07_Intersection/Question.java
  class Question (line 6) | public class Question {
    class Result (line 8) | public static class Result {
      method Result (line 11) | public Result(LinkedListNode tail, int size) {
    method getTailAndSize (line 17) | public static Result getTailAndSize(LinkedListNode list) {
    method getKthNode (line 29) | public static LinkedListNode getKthNode(LinkedListNode head, int k) {
    method findIntersection (line 38) | public static LinkedListNode findIntersection(LinkedListNode list1, Li...
    method main (line 67) | public static void main(String[] args) {

FILE: Java/Ch 02. Linked Lists/Q2_08_Loop_Detection/Question.java
  class Question (line 5) | public class Question {
    method FindBeginning (line 7) | public static LinkedListNode FindBeginning(LinkedListNode head) {
    method main (line 38) | public static void main(String[] args) {

FILE: Java/Ch 03. Stacks and Queues/Introduction/MyQueue.java
  class MyQueue (line 5) | public class MyQueue<T> {
    class QueueNode (line 6) | private static class QueueNode<T> {
      method QueueNode (line 10) | public QueueNode(T data) {
    method add (line 18) | public void add(T item) {
    method remove (line 29) | public T remove() {
    method peek (line 39) | public T peek() {
    method isEmpty (line 44) | public boolean isEmpty() {

FILE: Java/Ch 03. Stacks and Queues/Introduction/MyStack.java
  class MyStack (line 5) | public class MyStack<T> {
    class StackNode (line 6) | private static class StackNode<T> {
      method StackNode (line 10) | public StackNode(T data) {
      method getData (line 14) | public T getData() {
    method pop (line 21) | public T pop() {
    method push (line 28) | public void push(T item) {
    method peek (line 34) | public T peek() {
    method isEmpty (line 39) | public boolean isEmpty() {

FILE: Java/Ch 03. Stacks and Queues/Introduction/QueueTester.java
  class QueueTester (line 9) | public class QueueTester {
    method main (line 11) | public static void main(String[] args) {

FILE: Java/Ch 03. Stacks and Queues/Introduction/StackTester.java
  class StackTester (line 8) | public class StackTester {
    method main (line 10) | public static void main(String[] args) {

FILE: Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/FixedMultiStack.java
  class FixedMultiStack (line 7) | public class FixedMultiStack {
    method FixedMultiStack (line 13) | public FixedMultiStack(int stackSize) {
    method push (line 20) | public void push(int stackNum, int value) throws FullStackException {
    method pop (line 32) | public int pop(int stackNum) {
    method peek (line 45) | public int peek(int stackNum) {
    method isEmpty (line 53) | public boolean isEmpty(int stackNum) {
    method isFull (line 58) | public boolean isFull(int stackNum) {
    method indexOfTop (line 63) | private int indexOfTop(int stackNum) {
    method getValues (line 69) | public int[] getValues() {
    method getStackValues (line 73) | public int[] getStackValues(int stackNum) {
    method stackToString (line 81) | public String stackToString(int stackNum) {

FILE: Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/FullStackException.java
  class FullStackException (line 3) | public class FullStackException extends Exception {
    method FullStackException (line 6) | public FullStackException(){
    method FullStackException (line 10) | public FullStackException(String message){

FILE: Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/MultiStack.java
  class MultiStack (line 7) | public class MultiStack {
    class StackInfo (line 12) | private class StackInfo {
      method StackInfo (line 14) | public StackInfo(int start, int capacity) {
      method isWithinStackCapacity (line 22) | public boolean isWithinStackCapacity(int index) {
      method lastCapacityIndex (line 34) | public int lastCapacityIndex() {
      method lastElementIndex (line 38) | public int lastElementIndex() {
      method isFull (line 42) | public boolean isFull() {
      method isEmpty (line 46) | public boolean isEmpty() {
    method MultiStack (line 54) | public MultiStack(int numberOfStacks, int defaultSize) {
    method numberOfElements (line 64) | public int numberOfElements() {
    method allStacksAreFull (line 73) | public boolean allStacksAreFull() {
    method adjustIndex (line 78) | private int adjustIndex(int index) {
    method nextIndex (line 88) | private int nextIndex(int index) {
    method previousIndex (line 93) | private int previousIndex(int index) {
    method shift (line 101) | private void shift(int stackNum) {
    method expand (line 128) | private void expand(int stackNum) {
    method push (line 137) | public void push(int stackNum, int value) throws FullStackException {
    method pop (line 156) | public int pop(int stackNum) throws Exception {
    method peek (line 171) | public int peek(int stackNum) {
    method getValues (line 176) | public int[] getValues() {
    method getStackValues (line 180) | public int[] getStackValues(int stackNum) {
    method stackToString (line 189) | public String stackToString(int stackNum) {

FILE: Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method printStacks (line 6) | public static void printStacks(FixedMultiStack stacks) {
    method main (line 10) | public static void main(String [] args) throws Exception  {

FILE: Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method printStacks (line 6) | public static void printStacks(MultiStack stacks) {
    method main (line 13) | public static void main(String [] args) throws Exception  {

FILE: Java/Ch 03. Stacks and Queues/Q3_02_Stack_Min/NodeWithMin.java
  class NodeWithMin (line 3) | class NodeWithMin {
    method NodeWithMin (line 6) | public NodeWithMin(int v, int min){

FILE: Java/Ch 03. Stacks and Queues/Q3_02_Stack_Min/Question.java
  class Question (line 3) | public class Question {
    method main (line 4) | public static void main(String[] args) {

FILE: Java/Ch 03. Stacks and Queues/Q3_02_Stack_Min/StackWithMin.java
  class StackWithMin (line 5) | public class StackWithMin extends Stack<NodeWithMin> {
    method push (line 6) | public void push(int value) {
    method min (line 11) | public int min() {

FILE: Java/Ch 03. Stacks and Queues/Q3_02_Stack_Min/StackWithMin2.java
  class StackWithMin2 (line 5) | public class StackWithMin2 extends Stack<Integer> {
    method StackWithMin2 (line 8) | public StackWithMin2() {
    method push (line 12) | public void push(int value){
    method pop (line 19) | public Integer pop() {
    method min (line 27) | public int min() {

FILE: Java/Ch 03. Stacks and Queues/Q3_03_Stack_of_Plates/Node.java
  class Node (line 3) | public class Node {
    method Node (line 7) | public Node(int value) {

FILE: Java/Ch 03. Stacks and Queues/Q3_03_Stack_of_Plates/Question.java
  class Question (line 3) | public class Question {
    method main (line 4) | public static void main(String[] args) {

FILE: Java/Ch 03. Stacks and Queues/Q3_03_Stack_of_Plates/SetOfStacks.java
  class SetOfStacks (line 6) | public class SetOfStacks {
    method SetOfStacks (line 10) | public SetOfStacks(int capacity) {
    method getLastStack (line 14) | public Stack getLastStack() {
    method push (line 21) | public void push(int v) {
    method pop (line 32) | public int pop() {
    method popAt (line 42) | public int popAt(int index) {
    method leftShift (line 46) | public int leftShift(int index, boolean removeTop) {
    method isEmpty (line 60) | public boolean isEmpty() {

FILE: Java/Ch 03. Stacks and Queues/Q3_03_Stack_of_Plates/Stack.java
  class Stack (line 5) | public class Stack {
    method Stack (line 11) | public Stack(int capacity) {
    method isFull (line 15) | public boolean isFull() {
    method join (line 19) | public void join(Node above, Node below) {
    method push (line 24) | public boolean push(int v) {
    method pop (line 34) | public int pop() {
    method isEmpty (line 42) | public boolean isEmpty() {
    method removeBottom (line 46) | public int removeBottom() {

FILE: Java/Ch 03. Stacks and Queues/Q3_04_Queue_via_Stacks/MyQueue.java
  class MyQueue (line 5) | public class MyQueue<T> {
    method MyQueue (line 8) | public MyQueue() {
    method size (line 13) | public int size() {
    method add (line 17) | public void add(T value) {
    method shiftStacks (line 25) | private void shiftStacks() {
    method peek (line 33) | public T peek() {
    method remove (line 38) | public T remove() {

FILE: Java/Ch 03. Stacks and Queues/Q3_04_Queue_via_Stacks/Question.java
  class Question (line 8) | public class Question {
    method main (line 9) | public static void main(String[] args) {

FILE: Java/Ch 03. Stacks and Queues/Q3_05_Sort_Stack/Question.java
  class Question (line 7) | public class Question {
    method mergesort (line 8) | public static Stack<Integer> mergesort(Stack<Integer> inStack) {
    method sort (line 48) | public static void sort(Stack<Integer> s) {
    method main (line 65) | public static void main(String [] args) {

FILE: Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/Animal.java
  class Animal (line 3) | public abstract class Animal {
    method Animal (line 6) | public Animal(String n) {
    method name (line 10) | public abstract String name();
    method setOrder (line 12) | public void setOrder(int ord) {
    method getOrder (line 16) | public int getOrder() {
    method isOlderThan (line 20) | public boolean isOlderThan(Animal a) {

FILE: Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/AnimalQueue.java
  class AnimalQueue (line 5) | public class AnimalQueue {
    method enqueue (line 10) | public void enqueue(Animal a) {
    method dequeueAny (line 20) | public Animal dequeueAny() {
    method peek (line 35) | public Animal peek() {
    method size (line 50) | public int size() {
    method dequeueDogs (line 54) | public Dog dequeueDogs() {
    method peekDogs (line 58) | public Dog peekDogs() {
    method dequeueCats (line 62) | public Cat dequeueCats() {
    method peekCats (line 66) | public Cat peekCats() {

FILE: Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/Cat.java
  class Cat (line 3) | public class Cat extends Animal {
    method Cat (line 4) | public Cat(String n) {
    method name (line 8) | public String name() {

FILE: Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/Dog.java
  class Dog (line 3) | public class Dog extends Animal {
    method Dog (line 4) | public Dog(String n) {
    method name (line 8) | public String name() {

FILE: Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/Question.java
  class Question (line 3) | public class Question {
    method main (line 6) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Introduction/Traversals.java
  class Traversals (line 5) | public class Traversals {
    method visit (line 6) | public static void visit(TreeNode node) {
    method inOrderTraversal (line 12) | public static void inOrderTraversal(TreeNode node) {
    method preOrderTraversal (line 20) | public static void preOrderTraversal(TreeNode node) {
    method postOrderTraversal (line 28) | public static void postOrderTraversal(TreeNode node) {
    method main (line 36) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_01_Route_Between_Nodes/Graph.java
  class Graph (line 3) | public class Graph {
    method Graph (line 7) | public Graph() {
    method addNode (line 12) | public void addNode(Node x) {
    method getNodes (line 21) | public Node[] getNodes() {

FILE: Java/Ch 04. Trees and Graphs/Q4_01_Route_Between_Nodes/Node.java
  class Node (line 3) | class Node {
    method Node (line 8) | public Node(String vertex, int adjacentLength) {
    method addAdjacent (line 14) | public void addAdjacent(Node x) {
    method getAdjacent (line 22) | public Node[] getAdjacent() {
    method getVertex (line 25) | public String getVertex() {

FILE: Java/Ch 04. Trees and Graphs/Q4_01_Route_Between_Nodes/Question.java
  class Question (line 5) | public class Question {
    type State (line 6) | public enum State {
    method main (line 10) | public static void main(String a[])
    method createNewGraph (line 19) | public static Graph createNewGraph()
    method search (line 42) | public static boolean search(Graph g,Node start,Node end) {

FILE: Java/Ch 04. Trees and Graphs/Q4_02_Minimal_Tree/Question.java
  class Question (line 5) | public class Question {
    method main (line 6) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_03_List_of_Depths/QuestionBFS.java
  class QuestionBFS (line 9) | public class QuestionBFS {
    method createLevelLinkedList (line 11) | public static ArrayList<LinkedList<TreeNode>> createLevelLinkedList(Tr...
    method printResult (line 38) | public static void printResult(ArrayList<LinkedList<TreeNode>> result){
    method main (line 52) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_03_List_of_Depths/QuestionDFS.java
  class QuestionDFS (line 9) | public class QuestionDFS {
    method createLevelLinkedList (line 11) | public static void createLevelLinkedList(TreeNode root, ArrayList<Link...
    method createLevelLinkedList (line 27) | public static ArrayList<LinkedList<TreeNode>> createLevelLinkedList(Tr...
    method printResult (line 33) | public static void printResult(ArrayList<LinkedList<TreeNode>> result){
    method main (line 47) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_04_Check_Balanced/QuestionBrute.java
  class QuestionBrute (line 6) | public class QuestionBrute {
    method getHeight (line 8) | public static int getHeight(TreeNode root) {
    method isBalanced (line 15) | public static boolean isBalanced(TreeNode root) {
    method main (line 28) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_04_Check_Balanced/QuestionImproved.java
  class QuestionImproved (line 4) | public class QuestionImproved {
    method checkHeight (line 6) | public static int checkHeight(TreeNode root) {
    method isBalanced (line 24) | public static boolean isBalanced(TreeNode root) {
    method main (line 28) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_05_Validate_BST/IntWrapper.java
  class IntWrapper (line 3) | public class IntWrapper {
    method IntWrapper (line 4) | public IntWrapper(int m) {

FILE: Java/Ch 04. Trees and Graphs/Q4_05_Validate_BST/Question.java
  class Question (line 5) | public class Question {
    method checkBST (line 8) | public static boolean checkBST(TreeNode node) {
    method checkBST (line 13) | public static boolean checkBST(TreeNode n, boolean isLeft) {
    method main (line 46) | public static void main(String[] args) {
    method test (line 56) | public static void test() {

FILE: Java/Ch 04. Trees and Graphs/Q4_05_Validate_BST/QuestionB.java
  class QuestionB (line 6) | public class QuestionB {
    method checkBST (line 7) | public static boolean checkBST(TreeNode n, Integer min, Integer max) {
    method checkBST (line 21) | public static boolean checkBST(TreeNode n) {
    method checkBSTAlternate (line 25) | public static boolean checkBSTAlternate(TreeNode n) {
    method checkBSTAlternate (line 29) | public static boolean checkBSTAlternate(TreeNode n, IntWrapper min, In...
    method createTestTree (line 61) | public static TreeNode createTestTree() {
    method main (line 84) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_06_Successor/Question.java
  class Question (line 5) | public class Question {
    method inorderSucc (line 7) | public static TreeNode inorderSucc(TreeNode n) {
    method leftMostChild (line 25) | public static TreeNode leftMostChild(TreeNode n) {
    method main (line 35) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/DFS/Graph.java
  class Graph (line 6) | public class Graph {
    method getOrCreateNode (line 10) | public Project getOrCreateNode(String name) {
    method addEdge (line 20) | public void addEdge(String startName, String endName) {
    method getNodes (line 26) | public ArrayList<Project> getNodes() {

FILE: Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/DFS/Project.java
  class Project (line 6) | public class Project {
    type State (line 7) | public enum State {COMPLETE, PARTIAL, BLANK}
    method Project (line 13) | public Project(String n) {
    method getName (line 17) | public String getName() {
    method addNeighbor (line 21) | public void addNeighbor(Project node) {
    method getState (line 28) | public State getState() {
    method setState (line 32) | public void setState(State st) {
    method getChildren (line 36) | public ArrayList<Project> getChildren() {

FILE: Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/DFS/Question.java
  class Question (line 6) | public class Question {
    method buildGraph (line 12) | public static Graph buildGraph(String[] projects, String[][] dependenc...
    method doDFS (line 24) | public static boolean doDFS(Project project, Stack<Project> stack) {
    method orderProjects (line 43) | public static Stack<Project> orderProjects(ArrayList<Project> projects) {
    method convertToStringList (line 55) | public static String[] convertToStringList(Stack<Project> projects) {
    method findBuildOrder (line 63) | public static Stack<Project> findBuildOrder(String[] projects, String[...
    method buildOrderWrapper (line 68) | public static String[] buildOrderWrapper(String[] projects, String[][]...
    method main (line 75) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/EdgeRemoval/Graph.java
  class Graph (line 6) | public class Graph {
    method getOrCreateNode (line 10) | public Project getOrCreateNode(String name) {
    method addEdge (line 20) | public void addEdge(String startName, String endName) {
    method getNodes (line 26) | public ArrayList<Project> getNodes() {

FILE: Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/EdgeRemoval/Project.java
  class Project (line 6) | public class Project {
    method Project (line 12) | public Project(String n) {
    method getName (line 16) | public String getName() {
    method addNeighbor (line 20) | public void addNeighbor(Project node) {
    method incrementDependencies (line 28) | public void incrementDependencies() {
    method getChildren (line 32) | public ArrayList<Project> getChildren() {
    method decrementDependencies (line 36) | public void decrementDependencies() {
    method getNumberDependencies (line 40) | public int getNumberDependencies() {

FILE: Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/EdgeRemoval/Question.java
  class Question (line 5) | public class Question {
    method buildGraph (line 11) | public static Graph buildGraph(String[] projects, String[][] dependenc...
    method addNonDependent (line 28) | public static int addNonDependent(Project[] order, ArrayList<Project> ...
    method orderProjects (line 38) | public static Project[] orderProjects(ArrayList<Project> projects) {
    method convertToStringList (line 69) | public static String[] convertToStringList(Project[] projects) {
    method findBuildOrder (line 77) | public static Project[] findBuildOrder(String[] projects, String[][] d...
    method buildOrderWrapper (line 83) | public static String[] buildOrderWrapper(String[] projects, String[][]...
    method main (line 90) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/Question.java
  class Question (line 5) | public class Question {
    method covers (line 11) | public static int covers(TreeNode root, TreeNode p, TreeNode q) {
    method commonAncestor (line 21) | public static TreeNode commonAncestor(TreeNode root, TreeNode p, TreeN...
    method main (line 45) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method commonAncestor (line 6) | public static TreeNode commonAncestor(TreeNode p, TreeNode q) {
    method isOnPath (line 19) | public static boolean isOnPath(TreeNode ancestor, TreeNode node) {
    method main (line 26) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method commonAncestor (line 6) | public static TreeNode commonAncestor(TreeNode p, TreeNode q) {
    method goUpBy (line 18) | public static TreeNode goUpBy(TreeNode node, int delta) {
    method depth (line 26) | public static int depth(TreeNode node) {
    method main (line 35) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionC.java
  class QuestionC (line 5) | public class QuestionC {
    method commonAncestor (line 7) | public static TreeNode commonAncestor(TreeNode root, TreeNode p, TreeN...
    method covers (line 25) | public static boolean covers(TreeNode root, TreeNode p) {
    method getSibling (line 31) | public static TreeNode getSibling(TreeNode node) {
    method main (line 40) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionD.java
  class QuestionD (line 5) | public class QuestionD {
    method commonAncestor (line 7) | public static TreeNode commonAncestor(TreeNode root, TreeNode p, TreeN...
    method ancestorHelper (line 14) | public static TreeNode ancestorHelper(TreeNode root, TreeNode p, TreeN...
    method covers (line 28) | public static boolean covers(TreeNode root, TreeNode p) {
    method main (line 36) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionE.java
  class QuestionE (line 5) | public class QuestionE {
    class Result (line 6) | public static class Result {
      method Result (line 9) | public Result(TreeNode n, boolean isAnc) {
    method commonAncestorHelper (line 15) | public static Result commonAncestorHelper(TreeNode root, TreeNode p, T...
    method commonAncestor (line 46) | public static TreeNode commonAncestor(TreeNode root, TreeNode p, TreeN...
    method main (line 54) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionEBad.java
  class QuestionEBad (line 5) | public class QuestionEBad {
    method commonAncestorBad (line 6) | public static TreeNode commonAncestorBad(TreeNode root, TreeNode p, Tr...
    method main (line 33) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionF.java
  class QuestionF (line 5) | public class QuestionF {
    method commonAncestor (line 7) | public static TreeNode commonAncestor(TreeNode root, TreeNode p, TreeN...
    method main (line 26) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/Tester.java
  class Tester (line 7) | public class Tester {
    method resultToString (line 8) | public static String resultToString(String s, TreeNode x, TreeNode y, ...
    method main (line 18) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_09_BST_Sequences/Question.java
  class Question (line 8) | public class Question {
    method weaveLists (line 10) | public static void weaveLists(LinkedList<Integer> first, LinkedList<In...
    method allSequences (line 39) | public static ArrayList<LinkedList<Integer>> allSequences(TreeNode nod...
    method main (line 65) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_10_Check_Subtree/QuestionA.java
  class QuestionA (line 6) | public class QuestionA {
    method containsTree (line 8) | public static boolean containsTree(TreeNode t1, TreeNode t2) {
    method getOrderString (line 18) | public static void getOrderString(TreeNode node, StringBuilder sb) {
    method main (line 28) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_10_Check_Subtree/QuestionB.java
  class QuestionB (line 6) | public class QuestionB {
    method containsTree (line 8) | public static boolean containsTree(TreeNode t1, TreeNode t2) {
    method subTree (line 18) | public static boolean subTree(TreeNode r1, TreeNode r2) {
    method matchTree (line 30) | public static boolean matchTree(TreeNode r1, TreeNode r2) {
    method main (line 42) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_11_Random_Node/Question.java
  class Question (line 3) | public class Question {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_11_Random_Node/Tree.java
  class Tree (line 5) | public class Tree {
    method insertInOrder (line 8) | public void insertInOrder(int value) {
    method size (line 16) | public int size() {
    method getRandomNode (line 20) | public TreeNode getRandomNode() {

FILE: Java/Ch 04. Trees and Graphs/Q4_11_Random_Node/TreeNode.java
  class TreeNode (line 8) | public class TreeNode {
    method TreeNode (line 14) | public TreeNode(int d) {
    method insertInOrder (line 19) | public void insertInOrder(int d) {
    method size (line 36) | public int size() {
    method find (line 40) | public TreeNode find(int d) {
    method getRandomNode (line 51) | public TreeNode getRandomNode() {
    method getIthNode (line 64) | public TreeNode getIthNode(int i) {

FILE: Java/Ch 04. Trees and Graphs/Q4_12_Paths_with_Sum/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method countPathsWithSum (line 7) | public static int countPathsWithSum(TreeNode root, int targetSum) {
    method countPathsWithSumFromNode (line 21) | public static int countPathsWithSumFromNode(TreeNode node, int targetS...
    method main (line 37) | public static void main(String [] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_12_Paths_with_Sum/QuestionB.java
  class QuestionB (line 6) | public class QuestionB {
    method countPathsWithSum (line 8) | public static int countPathsWithSum(TreeNode root, int targetSum) {
    method countPathsWithSum (line 12) | public static int countPathsWithSum(TreeNode node, int targetSum, int ...
    method incrementHashTable (line 37) | public static void incrementHashTable(HashMap<Integer, Integer> hashTa...
    method main (line 46) | public static void main(String [] args) {

FILE: Java/Ch 04. Trees and Graphs/Q4_12_Paths_with_Sum/Tester.java
  class Tester (line 6) | public class Tester {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_01_Insertion/Question.java
  class Question (line 5) | public class Question {
    method updateBits (line 7) | public static int updateBits(int n, int m, int i, int j) {
    method main (line 31) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_02_Binary_to_String/Question.java
  class Question (line 3) | public class Question {
    method printBinary (line 4) | public static String printBinary(double num) {
    method printBinary2 (line 28) | public static String printBinary2(double num) {
    method main (line 52) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method getBit (line 7) | public static boolean getBit(int num, int i) {
    method longestSequence (line 11) | public static int longestSequence(int n) {
    method longestSequenceOf1s (line 21) | public static int longestSequenceOf1s(int n, int indexToIgnore) {
    method main (line 35) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method longestSequence (line 7) | public static int longestSequence(int n) {
    method getAlternatingSequences (line 16) | public static ArrayList<Integer> getAlternatingSequences(int n) {
    method findLongestSequence (line 36) | public static int findLongestSequence(ArrayList<Integer> seq) {
    method main (line 58) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/QuestionC.java
  class QuestionC (line 3) | public class QuestionC {
    method getMaxSequence (line 9) | public static int getMaxSequence(int[] sequences) { /* 1s, then 0s, th...
    method shift (line 19) | public static void shift(int[] sequences) {
    method longestSequence (line 25) | public static int longestSequence(int n) {
    method main (line 53) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/QuestionD.java
  class QuestionD (line 3) | public class QuestionD {
    method flipBit (line 5) | public static int flipBit(int a) {
    method main (line 26) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/Tester.java
  class Tester (line 3) | public class Tester {
    method checkRange (line 5) | public static boolean checkRange(int start, int range) {
    method main (line 27) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_04_Next_Number/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method countOnes (line 5) | public static int countOnes(int i) {
    method countZeros (line 16) | public static int countZeros(int i) {
    method hasValidNext (line 20) | public static boolean hasValidNext(int i) {
    method hasValidPrev (line 39) | public static boolean hasValidPrev(int i) {
    method getNextSlow (line 49) | public static int getNextSlow(int i) {
    method getPrevSlow (line 61) | public static int getPrevSlow(int i) {
    method main (line 73) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_04_Next_Number/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method getNext (line 5) | public static int getNext(int n) {
    method getPrev (line 50) | public static int getPrev(int n) {
    method binPrint (line 105) | public static void binPrint(int i) {
    method main (line 109) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_04_Next_Number/QuestionC.java
  class QuestionC (line 3) | public class QuestionC {
    method getNextArith (line 4) | public static int getNextArith(int n) {
    method getPrevArith (line 34) | public static int getPrevArith(int n) {
    method binPrint (line 62) | public static void binPrint(int i) {
    method main (line 66) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_04_Next_Number/Tester.java
  class Tester (line 3) | public class Tester {
    method binPrint (line 4) | public static void binPrint(int i) {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_06_Conversion/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method bitSwapRequired (line 6) | public static int bitSwapRequired(int a, int b) {
    method main (line 16) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_06_Conversion/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method bitSwapRequired (line 6) | public static int bitSwapRequired(int a, int b){
    method main (line 22) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_06_Conversion/Tester.java
  class Tester (line 5) | public class Tester {
    method bitSwapRequired (line 6) | public static int bitSwapRequired(int a, int b) {
    method bitSwapRequired2 (line 14) | public static int bitSwapRequired2(int a, int b){
    method main (line 22) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_07_Pairwise_Swap/Question.java
  class Question (line 5) | public class Question {
    method swapOddEvenBits (line 7) | public static int swapOddEvenBits(int x) {
    method main (line 11) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Q5_08_Draw_Line/Question.java
  class Question (line 3) | public class Question {
    method computeByteNum (line 4) | public static int computeByteNum(int width, int x, int y) {
    method drawLine (line 8) | public static void drawLine(byte[] screen, int width, int x1, int x2, ...
    method printByte (line 45) | public static void printByte(byte b) {
    method printScreen (line 52) | public static void printScreen(byte[] screen, int width) {
    method main (line 63) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Sample_Code/RightShifts.java
  class RightShifts (line 5) | public class RightShifts {
    method repeatedArithmeticShift (line 6) | public static int repeatedArithmeticShift(int x, int count) {
    method repeatedLogicalShift (line 13) | public static int repeatedLogicalShift(int x, int count) {
    method main (line 20) | public static void main(String[] args) {

FILE: Java/Ch 05. Bit Manipulation/Sample_Code/Sample_Code.java
  class Sample_Code (line 5) | public class Sample_Code {
    method getBit (line 7) | public static boolean getBit(int num, int i) {
    method setBit (line 11) | public static int setBit(int num, int i) {
    method clearBit (line 15) | public static int clearBit(int num, int i) {
    method updateBit (line 20) | public static int updateBit(int num, int i, boolean bitIs1) {
    method clearBitsMSBthroughI (line 26) | public static int clearBitsMSBthroughI(int num, int i) {
    method clearBitsIthrough0 (line 31) | public static int clearBitsIthrough0(int num, int i) {
    method main (line 36) | public static void main(String[] args) {

FILE: Java/Ch 06. Math and Logic Puzzles/Introduction/PrimeNumbers.java
  class PrimeNumbers (line 3) | public class PrimeNumbers {
    method primeNaive (line 5) | public static boolean primeNaive(int n) {
    method primeSlightlyBetter (line 14) | public static boolean primeSlightlyBetter(int n) {
    method main (line 24) | public static void main(String[] args) {

FILE: Java/Ch 06. Math and Logic Puzzles/Introduction/SieveOfEratosthenes.java
  class SieveOfEratosthenes (line 3) | public class SieveOfEratosthenes {
    method crossOff (line 5) | public static void crossOff(boolean[] flags, int prime) {
    method getNextPrime (line 15) | public static int getNextPrime(boolean[] flags, int prime) {
    method init (line 23) | public static void init(boolean[] flags) {
    method prune (line 31) | public static int[] prune(boolean[] flags, int count) {
    method sieveOfEratosthenes (line 43) | public static boolean[] sieveOfEratosthenes(int max) {
    method main (line 60) | public static void main(String[] args) {

FILE: Java/Ch 06. Math and Logic Puzzles/Q6_05_Egg_Drop/Question.java
  class Question (line 3) | public class Question {
    method willBreak (line 8) | public static boolean willBreak(int floor) {
    method findBreakingPoint (line 14) | public static int findBreakingPoint(int floors) {
    method main (line 37) | public static void main(String[] args) {

FILE: Java/Ch 06. Math and Logic Puzzles/Q6_07_The_Apocalypse/Question.java
  class Question (line 5) | public class Question {
    method runOneFamily (line 6) | public static int[] runOneFamily() {
    method runNFamilies (line 21) | public static double runNFamilies(int n) {
    method main (line 32) | public static void main(String[] args) {

FILE: Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/Bottle.java
  class Bottle (line 3) | public class Bottle {
    method Bottle (line 7) | public Bottle(int id) {
    method getId (line 11) | public int getId() {
    method setAsPoisoned (line 15) | public void setAsPoisoned() {
    method isPoisoned (line 19) | public boolean isPoisoned() {

FILE: Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/QuestionA.java
  class QuestionA (line 6) | public class QuestionA {
    method findPoisonedBottle (line 7) | public static int findPoisonedBottle(ArrayList<Bottle> bottles, ArrayL...
    method runTestSet (line 34) | public static void runTestSet(ArrayList<Bottle> bottles, ArrayList<Tes...
    method createBottles (line 43) | public static ArrayList<Bottle> createBottles(int nBottles, int poison...
    method createTestStrips (line 60) | public static ArrayList<TestStrip> createTestStrips(int nTestStrips) {
    method main (line 68) | public static void main(String[] args) {

FILE: Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/QuestionB.java
  class QuestionB (line 7) | public class QuestionB {
    method createBottles (line 8) | public static ArrayList<Bottle> createBottles(int nBottles, int poison...
    method findPoisonedBottle (line 25) | public static int findPoisonedBottle(ArrayList<Bottle> bottles, ArrayL...
    method runTestSet (line 67) | public static void runTestSet(ArrayList<Bottle> bottles, ArrayList<Tes...
    method getTestStripIndexForDay (line 78) | public static int getTestStripIndexForDay(Bottle bottle, int day, int ...
    method getPositiveOnDay (line 90) | public static int getPositiveOnDay(ArrayList<TestStrip> testStrips, in...
    method createTestStrips (line 100) | public static ArrayList<TestStrip> createTestStrips(int nTestStrips) {
    method main (line 108) | public static void main(String[] args) {

FILE: Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/QuestionC.java
  class QuestionC (line 6) | public class QuestionC {
    method createBottles (line 7) | public static ArrayList<Bottle> createBottles(int nBottles, int poison...
    method findPoisonedBottle (line 24) | public static int findPoisonedBottle(ArrayList<Bottle> bottles, ArrayL...
    method runTests (line 31) | public static void runTests(ArrayList<Bottle> bottles, ArrayList<TestS...
    method getPositiveOnDay (line 46) | public static ArrayList<Integer> getPositiveOnDay(ArrayList<TestStrip>...
    method setBits (line 58) | public static int setBits(ArrayList<Integer> positive) {
    method createTestStrips (line 66) | public static ArrayList<TestStrip> createTestStrips(int nTestStrips) {
    method main (line 74) | public static void main(String[] args) {

FILE: Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/TestStrip.java
  class TestStrip (line 5) | public class TestStrip {
    method TestStrip (line 10) | public TestStrip(int id) {
    method getId (line 14) | public int getId() {
    method sizeDropsForDay (line 19) | private void sizeDropsForDay(int day) {
    method addDropOnDay (line 26) | public void addDropOnDay(int day, Bottle bottle) {
    method hasPoison (line 33) | private boolean hasPoison(ArrayList<Bottle> bottles) {
    method getLastWeeksBottles (line 43) | public ArrayList<Bottle> getLastWeeksBottles(int day) {
    method isPositiveOnDay (line 51) | public boolean isPositiveOnDay(int day) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/BlackJackCard.java
  class BlackJackCard (line 3) | public class BlackJackCard extends Card {
    method BlackJackCard (line 4) | public BlackJackCard(int c, Suit s) {
    method value (line 8) | public int value() {
    method minValue (line 18) | public int minValue() {
    method maxValue (line 26) | public int maxValue() {
    method isAce (line 34) | public boolean isAce() {
    method isFaceCard (line 38) | public boolean isFaceCard() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/BlackJackGameAutomator.java
  class BlackJackGameAutomator (line 5) | public class BlackJackGameAutomator {
    method BlackJackGameAutomator (line 10) | public BlackJackGameAutomator(int numPlayers) {
    method dealInitial (line 17) | public boolean dealInitial() {
    method getBlackJacks (line 30) | public ArrayList<Integer> getBlackJacks() {
    method playHand (line 40) | public boolean playHand(int i) {
    method playHand (line 45) | public boolean playHand(BlackJackHand hand) {
    method playAllHands (line 56) | public boolean playAllHands() {
    method getWinners (line 65) | public ArrayList<Integer> getWinners() {
    method initializeDeck (line 83) | public void initializeDeck() {
    method printHandsAndScore (line 98) | public void printHandsAndScore() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/BlackJackHand.java
  class BlackJackHand (line 5) | public class BlackJackHand extends Hand<BlackJackCard> {
    method BlackJackHand (line 6) | public BlackJackHand() {
    method score (line 10) | public int score() {
    method possibleScores (line 24) | private ArrayList<Integer> possibleScores() {
    method addCardToScoreList (line 35) | private void addCardToScoreList(BlackJackCard card, ArrayList<Integer>...
    method busted (line 49) | public boolean busted() {
    method is21 (line 53) | public boolean is21() {
    method isBlackJack (line 57) | public boolean isBlackJack() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/Card.java
  class Card (line 3) | public abstract class Card {
    method Card (line 12) | public Card(int c, Suit s) {
    method value (line 17) | public abstract int value();
    method suit (line 19) | public Suit suit() {
    method isAvailable (line 24) | public boolean isAvailable() {
    method markUnavailable (line 28) | public void markUnavailable() {
    method markAvailable (line 32) | public void markAvailable() {
    method print (line 36) | public void print() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/Deck.java
  class Deck (line 7) | public class Deck <T extends Card> {
    method Deck (line 11) | public Deck() {
    method setDeckOfCards (line 14) | public void setDeckOfCards(ArrayList<T> deckOfCards) {
    method shuffle (line 18) | public void shuffle() {
    method remainingCards (line 28) | public int remainingCards() {
    method dealHand (line 32) | public T[] dealHand(int number) {
    method dealCard (line 50) | public T dealCard() {
    method print (line 62) | public void print() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/Hand.java
  class Hand (line 5) | public class Hand <T extends Card> {
    method score (line 8) | public int score() {
    method addCard (line 16) | public void addCard(T card) {
    method print (line 20) | public void print() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/Question.java
  class Question (line 5) | public class Question {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/Suit.java
  type Suit (line 3) | public enum Suit {
    method Suit (line 10) | private Suit(int v) {
    method getValue (line 14) | public int getValue() {
    method getSuitFromValue (line 18) | public static Suit getSuitFromValue(int value) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Call.java
  class Call (line 6) | public class Call {
    method Call (line 16) | public Call(Caller c) {
    method setHandler (line 22) | public void setHandler(Employee e) {
    method reply (line 27) | public void reply(String message) {
    method getRank (line 31) | public Rank getRank() {
    method setRank (line 35) | public void setRank(Rank r) {
    method incrementRank (line 39) | public Rank incrementRank() {
    method disconnect (line 49) | public void disconnect() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/CallHandler.java
  class CallHandler (line 9) | public class CallHandler {
    method CallHandler (line 28) | public CallHandler() {
    method getHandlerForCall (line 51) | public Employee getHandlerForCall(Call call) {
    method dispatchCall (line 64) | public void dispatchCall(Caller caller) {
    method dispatchCall (line 70) | public void dispatchCall(Call call) {
    method assignCall (line 85) | public boolean assignCall(Employee emp) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Caller.java
  class Caller (line 3) | public class Caller {
    method Caller (line 6) | public Caller(int id, String nm) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Director.java
  class Director (line 3) | class Director extends Employee {
    method Director (line 4) | public Director(CallHandler callHandler) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Employee.java
  class Employee (line 6) | abstract class Employee {
    method Employee (line 11) | public Employee(CallHandler handler) {
    method receiveCall (line 16) | public void receiveCall(Call call) {
    method callCompleted (line 21) | public void callCompleted() {
    method escalateAndReassign (line 38) | public void escalateAndReassign() {
    method assignNewCall (line 53) | public boolean assignNewCall() {
    method isFree (line 61) | public boolean isFree() {
    method getRank (line 65) | public Rank getRank() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Manager.java
  class Manager (line 3) | class Manager extends Employee {
    method Manager (line 4) | public Manager(CallHandler callHandler) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Rank.java
  type Rank (line 3) | public enum Rank {
    method Rank (line 10) | private Rank(int v) {
    method getValue (line 14) | public int getValue() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Respondent.java
  class Respondent (line 3) | class Respondent extends Employee {
    method Respondent (line 4) | public Respondent(CallHandler callHandler) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Test.java
  class Test (line 3) | public class Test {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/CD.java
  class CD (line 3) | public class CD {

FILE: Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/CDPlayer.java
  class CDPlayer (line 3) | public class CDPlayer {
    method getPlaylist (line 7) | public Playlist getPlaylist() { return p; }
    method setPlaylist (line 8) | public void setPlaylist(Playlist p) { this.p = p; }
    method getCD (line 9) | public CD getCD() { return c; }
    method setCD (line 10) | public void setCD(CD c) { this.c = c; }
    method CDPlayer (line 12) | public CDPlayer(Playlist p) { this.p = p; }
    method CDPlayer (line 13) | public CDPlayer(CD c, Playlist p) {
    method CDPlayer (line 18) | public CDPlayer(CD c){ this.c = c; }
    method playSong (line 19) | public void playSong(Song s) {  }

FILE: Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/JukeBox.java
  class JukeBox (line 5) | public class JukeBox {
    method JukeBox (line 11) | public JukeBox(CDPlayer cdPlayer, User user, Set<CD> cdCollection,
    method getCurrentSong (line 20) | public Song getCurrentSong() { return ts.getCurrentSong();	}
    method setUser (line 21) | public void setUser(User u) { this.user = u;	}

FILE: Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/Playlist.java
  class Playlist (line 5) | public class Playlist {
    method Playlist (line 8) | public Playlist(Song song, Queue<Song> queue) {
    method getNextSongToPlay (line 14) | public Song getNextSongToPlay(){ return queue.peek(); }
    method queueUpSong (line 15) | public void queueUpSong(Song s){ queue.add(s); }

FILE: Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/Song.java
  class Song (line 3) | public class Song {
    method toString (line 5) | public String toString() { return songName; }

FILE: Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/SongSelector.java
  class SongSelector (line 4) | public class SongSelector {
    method SongSelector (line 6) | public SongSelector(Song s) { currentSong=s; }
    method setSong (line 7) | public void setSong(Song s) { currentSong = s;	}
    method getCurrentSong (line 8) | public Song getCurrentSong() { return currentSong;	}

FILE: Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/User.java
  class User (line 3) | public class User {
    method getName (line 5) | public String getName() { return name; }
    method setName (line 6) | public void setName(String name) {	this.name = name; }
    method getID (line 7) | public long getID() { return ID; }
    method setID (line 8) | public void setID(long iD) { ID = iD; }
    method User (line 10) | public User(String name, long iD) {
    method getUser (line 14) | public User getUser() { return this; }
    method addUser (line 15) | public static User addUser(String name, long iD){

FILE: Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/Bus.java
  class Bus (line 3) | public class Bus extends Vehicle {
    method Bus (line 4) | public Bus() {
    method canFitInSpot (line 9) | public boolean canFitInSpot(ParkingSpot spot) {
    method print (line 13) | public void print() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/Car.java
  class Car (line 3) | public class Car extends Vehicle {
    method Car (line 4) | public Car() {
    method canFitInSpot (line 9) | public boolean canFitInSpot(ParkingSpot spot) {
    method print (line 13) | public void print() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/Level.java
  class Level (line 4) | public class Level {
    method Level (line 10) | public Level(int flr, int numberSpots) {
    method availableSpots (line 29) | public int availableSpots() {
    method parkVehicle (line 34) | public boolean parkVehicle(Vehicle vehicle) {
    method parkStartingAtSpot (line 46) | private boolean parkStartingAtSpot(int spotNumber, Vehicle vehicle) {
    method findAvailableSpots (line 57) | private int findAvailableSpots(Vehicle vehicle) {
    method print (line 79) | public void print() {
    method spotFreed (line 92) | public void spotFreed() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/Motorcycle.java
  class Motorcycle (line 3) | public class Motorcycle extends Vehicle {
    method Motorcycle (line 4) | public Motorcycle() {
    method canFitInSpot (line 9) | public boolean canFitInSpot(ParkingSpot spot) {
    method print (line 13) | public void print() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/ParkingLot.java
  class ParkingLot (line 3) | public class ParkingLot {
    method ParkingLot (line 7) | public ParkingLot() {
    method parkVehicle (line 15) | public boolean parkVehicle(Vehicle vehicle) {
    method print (line 24) | public void print() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/ParkingSpot.java
  class ParkingSpot (line 3) | public class ParkingSpot {
    method ParkingSpot (line 10) | public ParkingSpot(Level lvl, int r, int n, VehicleSize sz) {
    method isAvailable (line 17) | public boolean isAvailable() {
    method canFitVehicle (line 23) | public boolean canFitVehicle(Vehicle vehicle) {
    method park (line 28) | public boolean park(Vehicle v) {
    method getRow (line 37) | public int getRow() {
    method getSpotNumber (line 41) | public int getSpotNumber() {
    method getSize (line 45) | public VehicleSize getSize() {
    method removeVehicle (line 50) | public void removeVehicle() {
    method print (line 55) | public void print() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/Question.java
  class Question (line 5) | public class Question {
    method main (line 10) | public static void main(String[] args) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/Vehicle.java
  class Vehicle (line 5) | public abstract class Vehicle {
    method getSpotsNeeded (line 11) | public int getSpotsNeeded() {
    method getSize (line 15) | public VehicleSize getSize() {
    method parkInSpot (line 20) | public void parkInSpot(ParkingSpot spot) {
    method clearSpots (line 25) | public void clearSpots() {
    method canFitInSpot (line 32) | public abstract boolean canFitInSpot(ParkingSpot spot);
    method print (line 33) | public abstract void print();

FILE: Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/VehicleSize.java
  type VehicleSize (line 3) | public enum VehicleSize {

FILE: Java/Ch 07. Object-Oriented Design/Q7_05_Online_Book_Reader/Book.java
  class Book (line 3) | public class Book {
    method Book (line 7) | public Book(int id, String det) {
    method update (line 12) | public void update() { }
    method getID (line 14) | public int getID() {
    method setID (line 18) | public void setID(int id) {
    method getDetails (line 22) | public String getDetails() {
    method setDetails (line 26) | public void setDetails(String details) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_05_Online_Book_Reader/Display.java
  class Display (line 3) | public class Display {
    method displayUser (line 8) | public void displayUser(User user) {
    method displayBook (line 13) | public void displayBook(Book book) {
    method refreshUsername (line 22) | public void refreshUsername() {
    method refreshTitle (line 26) | public void refreshTitle() {
    method refreshDetails (line 30) | public void refreshDetails() {
    method refreshPage (line 34) | public void refreshPage() {
    method turnPageForward (line 38) | public void turnPageForward() {
    method turnPageBackward (line 43) | public void turnPageBackward() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_05_Online_Book_Reader/Library.java
  class Library (line 5) | public class Library {
    method addBook (line 9) | public Book addBook(int id, String details) {
    method remove (line 18) | public boolean remove(Book b){
    method remove (line 22) | public boolean remove(int id) {
    method find (line 30) | public Book find(int id){

FILE: Java/Ch 07. Object-Oriented Design/Q7_05_Online_Book_Reader/OnlineReaderSystem.java
  class OnlineReaderSystem (line 3) | public class OnlineReaderSystem {
    method OnlineReaderSystem (line 11) | public OnlineReaderSystem() {
    method getLibrary (line 17) | public Library getLibrary() {
    method getUserManager (line 21) | public UserManager getUserManager() {
    method getDisplay (line 25) | public Display getDisplay() {
    method getActiveBook (line 29) | public Book getActiveBook() {
    method setActiveBook (line 33) | public void setActiveBook(Book book) {
    method getActiveUser (line 38) | public User getActiveUser() {
    method setActiveUser (line 42) | public void setActiveUser(User user) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_05_Online_Book_Reader/User.java
  class User (line 3) | public class User {
    method renewMembership (line 8) | public void renewMembership() {  }
    method User (line 10) | public User(int id, String details, int accountType) {
    method getID (line 17) | public int getID() { return userId; }
    method setID (line 18) | public void setID(int id) { userId = id; }
    method getDetails (line 19) | public String getDetails() { return details; }
    method setDetails (line 20) | public void setDetails(String details) { this.details = details; }
    method getAccountType (line 21) | public int getAccountType() { return accountType; }
    method setAccountType (line 22) | public void setAccountType(int accountType) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_05_Online_Book_Reader/UserManager.java
  class UserManager (line 5) | public class UserManager {
    method addUser (line 8) | public User addUser(int id, String details, int accountType) {
    method remove (line 17) | public boolean remove(User u) {
    method remove (line 21) | public boolean remove(int id) {
    method find (line 29) | public User find(int id){

FILE: Java/Ch 07. Object-Oriented Design/Q7_06_Jigsaw/Edge.java
  class Edge (line 3) | public class Edge {
    method Edge (line 8) | public Edge(Shape shape, String code) {
    method getCode (line 13) | private String getCode() {
    method _createMatchingEdge (line 17) | public Edge _createMatchingEdge() {
    method fitsWith (line 23) | public boolean fitsWith(Edge edge) {
    method setParentPiece (line 28) | public void setParentPiece(Piece parentPiece) {
    method getParentPiece (line 33) | public Piece getParentPiece() {
    method getShape (line 38) | public Shape getShape() {
    method toString (line 42) | public String toString() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_06_Jigsaw/Orientation.java
  type Orientation (line 3) | public enum Orientation {
    method getOpposite (line 6) | public Orientation getOpposite() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_06_Jigsaw/Piece.java
  class Piece (line 6) | public class Piece {
    method Piece (line 10) | public Piece(Edge[] edgeList) {
    method setEdgeAsOrientation (line 20) | public void setEdgeAsOrientation(Edge edge, Orientation orientation) {
    method getOrientation (line 26) | private Orientation getOrientation(Edge edge) {
    method rotateEdgesBy (line 36) | public void rotateEdgesBy(int numberRotations) {
    method isCorner (line 52) | public boolean isCorner() {
    method isBorder (line 65) | public boolean isBorder() {
    method getEdgeWithOrientation (line 76) | public Edge getEdgeWithOrientation(Orientation orientation) {
    method getMatchingEdge (line 81) | public Edge getMatchingEdge(Edge targetEdge) {
    method toString (line 90) | public String toString() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_06_Jigsaw/Puzzle.java
  class Puzzle (line 5) | public class Puzzle {
    method Puzzle (line 10) | public Puzzle(int size, LinkedList<Piece> pieces) {
    method groupPieces (line 16) | public void groupPieces(LinkedList<Piece> cornerPieces, LinkedList<Pie...
    method orientTopLeftCorner (line 29) | public void orientTopLeftCorner(Piece piece) {
    method isBorderIndex (line 44) | public boolean isBorderIndex(int location) {
    method getMatchingEdge (line 49) | private Edge getMatchingEdge(Edge targetEdge, LinkedList<Piece> pieces) {
    method setEdgeInSolution (line 60) | private void setEdgeInSolution(LinkedList<Piece> pieces, Edge edge, in...
    method getPieceListToSearch (line 68) | private LinkedList<Piece> getPieceListToSearch(LinkedList<Piece> corne...
    method fitNextEdge (line 79) | private boolean fitNextEdge(LinkedList<Piece> piecesToSearch, int row,...
    method solve (line 100) | public boolean solve() {
    method getCurrentSolution (line 121) | public Piece[][] getCurrentSolution() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_06_Jigsaw/Question.java
  class Question (line 6) | public class Question {
    method createRandomEdge (line 9) | public static Edge createRandomEdge(String code) {
    method createEdges (line 18) | public static Edge[] createEdges(Piece[][] puzzle, int column, int row) {
    method initializePuzzle (line 36) | public static LinkedList<Piece> initializePuzzle(int size) {
    method solutionToString (line 62) | public static String solutionToString(Piece[][] solution) {
    method validate (line 80) | public static boolean validate(Piece[][] solution) {
    method testSize (line 115) | public static boolean testSize(int size) {
    method main (line 127) | public static void main(String[] args) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_06_Jigsaw/Shape.java
  type Shape (line 3) | public enum Shape {
    method getOpposite (line 6) | public Shape getOpposite() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/AddRequest.java
  class AddRequest (line 5) | public class AddRequest {
    method AddRequest (line 11) | public AddRequest(User from, User to, Date date) {
    method getStatus (line 18) | public RequestStatus getStatus() {
    method getFromUser (line 22) | public User getFromUser() {
    method getToUser (line 26) | public User getToUser() {
    method getDate (line 30) | public Date getDate() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/Conversation.java
  class Conversation (line 5) | public abstract class Conversation {
    method getMessages (line 10) | public ArrayList<Message> getMessages() {
    method addMessage (line 14) | public boolean addMessage(Message m) {
    method getId (line 19) | public int getId() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/GroupChat.java
  class GroupChat (line 3) | public class GroupChat extends Conversation {
    method removeParticipant (line 4) | public void removeParticipant(User user) {
    method addParticipant (line 8) | public void addParticipant(User user) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/Message.java
  class Message (line 5) | public class Message {
    method Message (line 8) | public Message(String content, Date date) {
    method getContent (line 13) | public String getContent() {
    method getDate (line 17) | public Date getDate() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/PrivateChat.java
  class PrivateChat (line 3) | public class PrivateChat extends Conversation {
    method PrivateChat (line 4) | public PrivateChat(User user1, User user2) {
    method getOtherParticipant (line 9) | public User getOtherParticipant(User primary) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/RequestStatus.java
  type RequestStatus (line 3) | public enum RequestStatus {

FILE: Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/System.java
  class System (line 3) | public class System {

FILE: Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/User.java
  class User (line 7) | public class User {
    method User (line 19) | public User(int id, String accountName, String fullName) {
    method sendMessageToUser (line 25) | public boolean sendMessageToUser(User toUser, String content) {
    method sendMessageToGroupChat (line 35) | public boolean sendMessageToGroupChat(int groupId, String content) {
    method setStatus (line 44) | public void setStatus(UserStatus status) {
    method getStatus (line 48) | public UserStatus getStatus() {
    method addContact (line 52) | public boolean addContact(User user) {
    method receivedAddRequest (line 61) | public void receivedAddRequest(AddRequest req) {
    method sentAddRequest (line 68) | public void sentAddRequest(AddRequest req) {
    method removeAddRequest (line 75) | public void removeAddRequest(AddRequest req) {
    method requestAddUser (line 83) | public void requestAddUser(String accountName) {
    method addConversation (line 87) | public void addConversation(PrivateChat conversation) {
    method addConversation (line 92) | public void addConversation(GroupChat conversation) {
    method getId (line 96) | public int getId() {
    method getAccountName (line 100) | public String getAccountName() {
    method getFullName (line 104) | public String getFullName() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/UserManager.java
  class UserManager (line 7) | public class UserManager {
    method getInstance (line 13) | public static UserManager getInstance() {
    method addUser (line 20) | public void addUser(User fromUser, String toAccountName) {
    method approveAddRequest (line 27) | public void approveAddRequest(AddRequest req) {
    method rejectAddRequest (line 35) | public void rejectAddRequest(AddRequest req) {
    method userSignedOn (line 43) | public void userSignedOn(String accountName) {
    method userSignedOff (line 51) | public void userSignedOff(String accountName) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/UserStatus.java
  class UserStatus (line 3) | public class UserStatus {
    method UserStatus (line 6) | public UserStatus(UserStatusType type, String message) {
    method getStatusType (line 11) | public UserStatusType getStatusType() {
    method getMessage (line 15) | public String getMessage() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/UserStatusType.java
  type UserStatusType (line 3) | public enum UserStatusType {

FILE: Java/Ch 07. Object-Oriented Design/Q7_08_Othello/Automator.java
  class Automator (line 8) | public class Automator {
    method Automator (line 14) | private Automator() {
    method getInstance (line 23) | public static Automator getInstance() {
    method initialize (line 30) | public void initialize(Player[] ps) {
    method shuffle (line 35) | public void shuffle() {
    method removeLocation (line 45) | public void removeLocation(int r, int c) {
    method getLocation (line 54) | public Location getLocation(int index) {
    method playRandom (line 58) | public boolean playRandom() {
    method isOver (line 78) | public boolean isOver() {
    method printScores (line 85) | public void printScores() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_08_Othello/Board.java
  class Board (line 3) | public class Board {
    method Board (line 8) | public Board(int rows, int columns) {
    method initialize (line 12) | public void initialize() {
    method placeColor (line 27) | public boolean placeColor(int row, int column, Color color) {
    method flipSection (line 58) | private int flipSection(int row, int column, Color color, Direction d) {
    method getScoreForColor (line 103) | public int getScoreForColor(Color c) {
    method updateScore (line 111) | public void updateScore(Color newColor, int newPieces) {
    method printBoard (line 124) | public void printBoard() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_08_Othello/Color.java
  type Color (line 3) | public enum Color {

FILE: Java/Ch 07. Object-Oriented Design/Q7_08_Othello/Direction.java
  type Direction (line 3) | public enum Direction {

FILE: Java/Ch 07. Object-Oriented Design/Q7_08_Othello/Game.java
  class Game (line 3) | public class Game {
    method Game (line 10) | private Game() {
    method getInstance (line 18) | public static Game getInstance() {
    method getBoard (line 25) | public Board getBoard() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_08_Othello/Location.java
  class Location (line 3) | public class Location {
    method Location (line 6) | public Location(int r, int c) {
    method isSameAs (line 11) | public boolean isSameAs(int r, int c) {
    method getRow (line 15) | public int getRow() {
    method getColumn (line 19) | public int getColumn() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_08_Othello/Piece.java
  class Piece (line 3) | public class Piece {
    method Piece (line 6) | public Piece(Color c) {
    method flip (line 10) | public void flip() {
    method getColor (line 18) | public Color getColor() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_08_Othello/Player.java
  class Player (line 3) | public class Player {
    method Player (line 5) | public Player(Color c) {
    method getScore (line 9) | public int getScore() {
    method playPiece (line 13) | public boolean playPiece(int row, int column) {
    method getColor (line 17) | public Color getColor() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_08_Othello/Question.java
  class Question (line 3) | public class Question {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_09_Circular_Array/CircularArray.java
  class CircularArray (line 5) | public class CircularArray<T> implements Iterable<T> {
    method CircularArray (line 9) | public CircularArray(int size) {
    method convert (line 13) | private int convert(int index) {
    method rotate (line 20) | public void rotate(int shiftRight) {
    method get (line 24) | public T get(int i) {
    method set (line 31) | public void set(int i, T item) {
    method iterator (line 35) | public Iterator<T> iterator() {
    class CircularArrayIterator (line 39) | private class CircularArrayIterator implements Iterator<T> {
      method CircularArrayIterator (line 42) | public CircularArrayIterator() { }
      method hasNext (line 44) | @Override
      method next (line 49) | @Override
      method remove (line 55) | @Override

FILE: Java/Ch 07. Object-Oriented Design/Q7_09_Circular_Array/Question.java
  class Question (line 3) | public class Question {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_10_Minesweeper/Board.java
  class Board (line 9) | public class Board {
    method Board (line 18) | public Board(int r, int c, int b) {
    method initializeBoard (line 30) | private void initializeBoard() {
    method shuffleBoard (line 47) | private void shuffleBoard() {
    method inBounds (line 72) | private boolean inBounds(int row, int column) {
    method setNumberedCells (line 79) | private void setNumberedCells() {
    method printBoard (line 98) | public void printBoard(boolean showUnderside) {
    method flipCell (line 122) | private boolean flipCell(Cell cell) {
    method expandBlank (line 131) | public void expandBlank(Cell cell) {
    method playFlip (line 158) | public UserPlayResult playFlip(UserPlay play) {
    method getCellAtLocation (line 186) | public Cell getCellAtLocation(UserPlay play) {
    method getNumRemaining (line 195) | public int getNumRemaining() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_10_Minesweeper/Cell.java
  class Cell (line 3) | public class Cell {
    method Cell (line 11) | public Cell(int r, int c) {
    method setRowAndColumn (line 18) | public void setRowAndColumn(int r, int c) {
    method setBomb (line 23) | public void setBomb(boolean bomb) {
    method incrementNumber (line 28) | public void incrementNumber() {
    method getRow (line 32) | public int getRow() {
    method getColumn (line 36) | public int getColumn() {
    method isBomb (line 40) | public boolean isBomb() {
    method isBlank (line 44) | public boolean isBlank() {
    method isExposed (line 48) | public boolean isExposed() {
    method flip (line 52) | public boolean flip() {
    method toggleGuess (line 57) | public boolean toggleGuess() {
    method isGuess (line 64) | public boolean isGuess() {
    method toString (line 68) | @Override
    method getSurfaceState (line 73) | public String getSurfaceState() {
    method getUndersideState (line 83) | public String getUndersideState() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_10_Minesweeper/Game.java
  class Game (line 5) | public class Game {
    type GameState (line 6) | public enum GameState {
    method Game (line 16) | public Game(int r, int c, int b) {
    method initialize (line 23) | public boolean initialize() {
    method start (line 34) | public boolean start() {
    method printGameState (line 41) | public void printGameState() {
    method playGame (line 54) | private boolean playGame() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_10_Minesweeper/Question.java
  class Question (line 3) | public class Question {
    method main (line 4) | public static void main(String[] args) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_10_Minesweeper/UserPlay.java
  class UserPlay (line 3) | public class UserPlay {
    method UserPlay (line 8) | private UserPlay(int r, int c, boolean guess) {
    method fromString (line 14) | public static UserPlay fromString(String input) {
    method isGuess (line 36) | public boolean isGuess() {
    method isMove (line 40) | public boolean isMove() {
    method getColumn (line 44) | public int getColumn() {
    method setColumn (line 48) | public void setColumn(int column) {
    method getRow (line 52) | public int getRow() {
    method setRow (line 56) | public void setRow(int row) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_10_Minesweeper/UserPlayResult.java
  class UserPlayResult (line 3) | public class UserPlayResult {
    method UserPlayResult (line 6) | public UserPlayResult(boolean success, Game.GameState state) {
    method successfulMove (line 11) | public boolean successfulMove() {
    method getResultingState (line 15) | public Game.GameState getResultingState() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_11_File_System/Directory.java
  class Directory (line 5) | public class Directory extends Entry {
    method Directory (line 8) | public Directory(String n, Directory p) {
    method getContents (line 13) | protected ArrayList<Entry> getContents() {
    method size (line 17) | public int size() {
    method numberOfFiles (line 25) | public int numberOfFiles() {
    method deleteEntry (line 39) | public boolean deleteEntry(Entry entry) {
    method addEntry (line 43) | public void addEntry(Entry entry) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_11_File_System/Entry.java
  class Entry (line 3) | public abstract class Entry {
    method Entry (line 10) | public Entry(String n, Directory p) {
    method delete (line 16) | public boolean delete() {
    method size (line 23) | public abstract int size();
    method getFullPath (line 25) | public String getFullPath() {
    method getCreationTime (line 33) | public long getCreationTime() {
    method getLastUpdatedTime (line 37) | public long getLastUpdatedTime() {
    method getLastAccessedTime (line 41) | public long getLastAccessedTime() {
    method changeName (line 45) | public void changeName(String n) {
    method getName (line 49) | public String getName() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_11_File_System/File.java
  class File (line 3) | public class File extends Entry {
    method File (line 7) | public File(String n, Directory p, int sz) {
    method size (line 12) | public int size() {
    method getContents (line 16) | public String getContents() {
    method setContents (line 20) | public void setContents(String c) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_11_File_System/Question.java
  class Question (line 3) | public class Question {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 07. Object-Oriented Design/Q7_12_Hash_Table/Dummy.java
  class Dummy (line 3) | public class Dummy {
    method Dummy (line 6) | public Dummy(String n, int a) {
    method toString (line 11) | @Override
    method getAge (line 16) | public int getAge() {
    method getName (line 20) | public String getName() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_12_Hash_Table/Hasher.java
  class Hasher (line 5) | public class Hasher<K, V> {
    class LinkedListNode (line 6) | private static class LinkedListNode<K, V> {
      method LinkedListNode (line 11) | public LinkedListNode(K k, V v) {
      method printForward (line 16) | public String printForward() {
    method Hasher (line 27) | public Hasher(int capacity) {
    method put (line 37) | public V put(K key, V value) {
    method remove (line 56) | public V remove(K key) {
    method get (line 77) | public V get(K key) {
    method getNodeForKey (line 84) | private LinkedListNode<K, V> getNodeForKey(K key) {
    method getIndexForKey (line 97) | public int getIndexForKey(K key) {
    method printTable (line 101) | public void printTable() {

FILE: Java/Ch 07. Object-Oriented Design/Q7_12_Hash_Table/Question.java
  class Question (line 3) | public class Question {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Introduction/FibonacciA.java
  class FibonacciA (line 3) | public class FibonacciA {
    method fibonacci (line 4) | public static int fibonacci(int i) {
    method main (line 17) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Introduction/FibonacciB.java
  class FibonacciB (line 3) | public class FibonacciB {
    method fibonacci (line 4) | public static int fibonacci(int n) {
    method fibonacci (line 8) | public static int fibonacci(int i, int[] memo) {
    method main (line 21) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Introduction/FibonacciC.java
  class FibonacciC (line 3) | public class FibonacciC {
    method fibonacci (line 5) | public static int fibonacci(int n) {
    method main (line 21) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Introduction/FibonacciD.java
  class FibonacciD (line 3) | public class FibonacciD {
    method fibonacci (line 4) | public static int fibonacci(int n) {
    method main (line 19) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_01_Triple_Step/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method countWays (line 5) | public static int countWays(int n) {
    method main (line 15) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_01_Triple_Step/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method countWays (line 7) | public static int countWays(int n) {
    method countWays (line 13) | public static int countWays(int n, int[] memo) {
    method main (line 26) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_01_Triple_Step/Tester.java
  class Tester (line 3) | public class Tester {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_02_Robot_in_a_Grid/Point.java
  class Point (line 3) | public class Point {
    method Point (line 5) | public Point(int row, int column) {
    method toString (line 10) | @Override
    method hashCode (line 15) | @Override
    method equals (line 20) | @Override

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_02_Robot_in_a_Grid/QuestionA.java
  class QuestionA (line 7) | public class QuestionA {
    method getPath (line 9) | public static ArrayList<Point> getPath(boolean[][] maze) {
    method getPath (line 18) | public static boolean getPath(boolean[][] maze, int row, int col, Arra...
    method main (line 36) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_02_Robot_in_a_Grid/QuestionB.java
  class QuestionB (line 9) | public class QuestionB {
    method getPath (line 10) | public static ArrayList<Point> getPath(boolean[][] maze) {
    method getPath (line 20) | public static boolean getPath(boolean[][] maze, int row, int col, Arra...
    method main (line 45) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_02_Robot_in_a_Grid/Tester.java
  class Tester (line 7) | public class Tester {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_03_Magic_Index/Question.java
  class Question (line 7) | public class Question {
    method magicSlow (line 9) | public static int magicSlow(int[] array) {
    method magicFast (line 18) | public static int magicFast(int[] array, int start, int end) {
    method magicFast (line 32) | public static int magicFast(int[] array) {
    method getDistinctSortedArray (line 37) | public static int[] getDistinctSortedArray(int size) {
    method main (line 50) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_03_Magic_Index/QuestionB.java
  class QuestionB (line 7) | public class QuestionB {
    method magicSlow (line 9) | public static int magicSlow(int[] array) {
    method magicFast (line 18) | public static int magicFast(int[] array, int start, int end) {
    method magicFast (line 41) | public static int magicFast(int[] array) {
    method getSortedArray (line 46) | public static int[] getSortedArray(int size) {
    method main (line 52) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_04_Power_Set/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method getSubsets (line 7) | public static ArrayList<ArrayList<Integer>> getSubsets(ArrayList<Integ...
    method main (line 27) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_04_Power_Set/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method convertIntToSet (line 7) | public static ArrayList<Integer> convertIntToSet(int x, ArrayList<Inte...
    method getSubsets (line 19) | public static ArrayList<ArrayList<Integer>> getSubsets(ArrayList<Integ...
    method main (line 29) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_05_Recursive_Multiply/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method sum (line 7) | public static int sum(int x, int y) {
    method minProductHelper (line 12) | public static int minProductHelper(int smaller, int bigger) {
    method minProduct (line 32) | public static int minProduct(int a, int b) {
    method main (line 38) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_05_Recursive_Multiply/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method sum (line 7) | public static int sum(int x, int y) {
    method minProduct (line 12) | public static int minProduct(int smaller, int bigger, int[] memo) {
    method minProduct (line 37) | public static int minProduct(int a, int b) {
    method main (line 45) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_05_Recursive_Multiply/QuestionC.java
  class QuestionC (line 3) | public class QuestionC {
    method minProductHelper (line 7) | public static int minProductHelper(int smaller, int bigger) {
    method minProduct (line 27) | public static int minProduct(int a, int b) {
    method main (line 34) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_05_Recursive_Multiply/QuestionD.java
  class QuestionD (line 3) | public class QuestionD {
    method minProduct (line 9) | public static int minProduct(int a, int b) {
    method main (line 23) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_05_Recursive_Multiply/Tester.java
  class Tester (line 3) | public class Tester {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_06_Towers_of_Hanoi/Question.java
  class Question (line 3) | public class Question {
    method main (line 4) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_06_Towers_of_Hanoi/Tower.java
  class Tower (line 5) | public class Tower {
    method add (line 9) | public void add(int d) {
    method moveTopTo (line 17) | public void moveTopTo(Tower t) {
    method print (line 22) | public void print() {
    method moveDisks (line 26) | public void moveDisks(int quantity, Tower destination, Tower buffer){

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_07_Permutations_Without_Dups/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method getPerms (line 7) | public static ArrayList<String> getPerms(String str) {
    method insertCharAt (line 29) | public static String insertCharAt(String word, char c, int i) {
    method main (line 35) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_07_Permutations_Without_Dups/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method getPerms (line 6) | public static ArrayList<String> getPerms(String remainder) {
    method main (line 32) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_07_Permutations_Without_Dups/QuestionC.java
  class QuestionC (line 5) | public class QuestionC {
    method getPerms (line 7) | public static void getPerms(String prefix, String remainder, ArrayList...
    method getPerms (line 20) | public static ArrayList<String> getPerms(String str) {
    method main (line 26) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_08_Permutations_With_Dups/Question.java
  class Question (line 6) | public class Question {
    method buildFreqTable (line 7) | public static HashMap<Character, Integer> buildFreqTable(String s) {
    method printPerms (line 18) | public static void printPerms(HashMap<Character, Integer> map, String ...
    method printPerms (line 34) | public static ArrayList<String> printPerms(String s) {
    method main (line 41) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_09_Parens/QuestionA.java
  class QuestionA (line 6) | public class QuestionA {
    method insertInside (line 7) | public static String insertInside(String str, int leftIndex) {
    method generateParens (line 13) | public static Set<String> generateParens(int remaining) {
    method main (line 35) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_09_Parens/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method addParen (line 7) | public static void addParen(ArrayList<String> list, int leftRem, int r...
    method generateParens (line 21) | public static ArrayList<String> generateParens(int count) {
    method main (line 28) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_10_Paint_Fill/Question.java
  class Question (line 3) | public class Question {
    type Color (line 5) | public enum Color {
    method PrintColor (line 9) | public static String PrintColor(Color c) {
    method PrintScreen (line 25) | public static void PrintScreen(Color[][] screen) {
    method randomInt (line 34) | public static int randomInt(int n) {
    method PaintFill (line 38) | public static boolean PaintFill(Color[][] screen, int r, int c, Color ...
    method PaintFill (line 52) | public static boolean PaintFill(Color[][] screen, int r, int c, Color ...
    method main (line 57) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_11_Coins/Question.java
  class Question (line 3) | public class Question {
    method makeChangeHelper (line 4) | public static int makeChangeHelper(int total, int[] denoms, int index) {
    method makeChange (line 18) | public static int makeChange(int amount, int[] denoms) {
    method main (line 22) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_11_Coins/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method makeChange (line 5) | public static int makeChange(int n, int[] denoms) {
    method makeChangeHelper (line 10) | public static int makeChangeHelper(int total, int[] denoms, int index,...
    method main (line 33) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_11_Coins/Tester.java
  class Tester (line 3) | public class Tester {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_12_Eight_Queens/Question.java
  class Question (line 5) | public class Question {
    method checkValid (line 13) | public static boolean checkValid(Integer[] columns, int row1, int colu...
    method placeQueens (line 34) | public static void placeQueens(int row, Integer[] columns, ArrayList<I...
    method clear (line 47) | public static void clear(Integer[] columns) {
    method printBoard (line 53) | public static void printBoard(Integer[] columns) {
    method drawLine (line 70) | private static void drawLine() {
    method printBoards (line 79) | public static void printBoards(ArrayList<Integer[]> boards) {
    method main (line 86) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_13_Stack_of_Boxes/Box.java
  class Box (line 3) | public class Box {
    method Box (line 7) | public Box(int w, int h, int d) {
    method canBeUnder (line 13) | public boolean canBeUnder(Box b) {
    method canBeAbove (line 20) | public boolean canBeAbove(Box b) {
    method toString (line 30) | public String toString() {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_13_Stack_of_Boxes/BoxComparator.java
  class BoxComparator (line 5) | public class BoxComparator implements Comparator<Box> {
    method compare (line 6) | @Override

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_13_Stack_of_Boxes/QuestionA.java
  class QuestionA (line 6) | public class QuestionA {
    method createStack (line 7) | public static int createStack(ArrayList<Box> boxes) {
    method createStack (line 17) | public static int createStack(ArrayList<Box> boxes, int bottomIndex) {
    method main (line 31) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_13_Stack_of_Boxes/QuestionB.java
  class QuestionB (line 6) | public class QuestionB {
    method createStack (line 7) | public static int createStack(ArrayList<Box> boxes) {
    method createStack (line 18) | public static int createStack(ArrayList<Box> boxes, int bottomIndex, i...
    method main (line 37) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_13_Stack_of_Boxes/QuestionC.java
  class QuestionC (line 6) | public class QuestionC {
    method createStack (line 7) | public static int createStack(ArrayList<Box> boxes) {
    method createStack (line 13) | public static int createStack(ArrayList<Box> boxes, Box bottom, int of...
    method main (line 36) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_13_Stack_of_Boxes/Tester.java
  class Tester (line 6) | public class Tester {
    method createRandomBox (line 8) | public static Box createRandomBox() {
    method main (line 13) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_14_Boolean_Evaluation/Others.java
  class Others (line 5) | public class Others {
    type Term (line 6) | public enum Term {
    method reduce (line 16) | public static String reduce(String expression, int start, int end) {
    method evaluate (line 74) | public static boolean evaluate(String expression, int start, int end) {
    method isOperator (line 83) | public static boolean isOperator(char c) {
    method insertParensAround (line 94) | public static String insertParensAround(String expression, int ind) {
    method bruteForce (line 139) | public static int bruteForce(String expression, HashMap<String, Boolea...
    method countR (line 169) | public static int countR(String exp, boolean result, int start, int en...
    method countDP (line 211) | public static int countDP(String exp, boolean result, int start, int e...
    method total (line 258) | public static int total(int n) {
    method countDPEff (line 276) | public static int countDPEff(String exp, boolean result, int start, in...
    method main (line 315) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_14_Boolean_Evaluation/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method stringToBool (line 5) | public static boolean stringToBool(String c) {
    method countEval (line 9) | public static int countEval(String s, boolean result) {
    method main (line 42) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_14_Boolean_Evaluation/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method stringToBool (line 8) | public static boolean stringToBool(String c) {
    method countEval (line 12) | public static int countEval(String s, boolean result, HashMap<String, ...
    method countEval (line 47) | public static int countEval(String s, boolean result) {
    method main (line 51) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_14_Boolean_Evaluation/QuestionC.java
  class QuestionC (line 3) | public class QuestionC {
    method stringToBool (line 5) | public static boolean stringToBool(String c) {
    method countEval (line 9) | public static int countEval(String s, boolean result) {
    method main (line 67) | public static void main(String[] args) {

FILE: Java/Ch 08. Recursion and Dynamic Programming/Q8_14_Boolean_Evaluation/Tester.java
  class Tester (line 7) | public class Tester {
    method allEqual (line 9) | public static boolean allEqual(HashMap<String, Integer> map) {
    method getRandomOperator (line 20) | public static char getRandomOperator() {
    method getRandomExpression (line 27) | public static String getRandomExpression() {
    method main (line 43) | public static void main(String[] args) {

FILE: Java/Ch 09. Scalability and Memory Limits/Q9_02_Social_Network/BFSData.java
  class BFSData (line 7) | public class BFSData {
    method BFSData (line 11) | public BFSData(Person root) {
    method isFinished (line 17) | public boolean isFinished() {

FILE: Java/Ch 09. Scalability and Memory Limits/Q9_02_Social_Network/Machine.java
  class Machine (line 5) | public class Machine {
    method getPersonWithID (line 9) | public Person getPersonWithID(int personID) {

FILE: Java/Ch 09. Scalability and Memory Limits/Q9_02_Social_Network/PathNode.java
  class PathNode (line 5) | public class PathNode {
    method PathNode (line 8) | public PathNode(Person p, PathNode previous) {
    method getPerson (line 13) | public Person getPerson() {
    method collapse (line 17) | public LinkedList<Person> collapse(boolean startsWithRoot) {

FILE: Java/Ch 09. Scalability and Memory Limits/Q9_02_Social_Network/Person.java
  class Person (line 5) | public class Person {
    method getInfo (line 10) | public String getInfo() { return info; }
    method setInfo (line 11) | public void setInfo(String info) {
    method getFriends (line 15) | public ArrayList<Integer> getFriends() {
    method getID (line 19) | public int getID() { return personID; }
    method addFriend (line 20) | public void addFriend(int id) { friends.add(id); }
    method Person (line 22) | public Person(int id) {

FILE: Java/Ch 09. Scalability and Memory Limits/Q9_02_Social_Network/QuestionA.java
  class QuestionA (line 9) | public class QuestionA {
    method findPathBFS (line 10) | public static LinkedList<Person> findPathBFS(HashMap<Integer, Person> ...
    method main (line 35) | public static void main(String[] args) {

FILE: Java/Ch 09. Scalability and Memory Limits/Q9_02_Social_Network/QuestionB.java
  class QuestionB (line 9) | public class QuestionB {
    method mergePaths (line 11) | public static LinkedList<Person> mergePaths(BFSData bfs1, BFSData bfs2...
    method searchLevel (line 22) | public static Person searchLevel(HashMap<Integer, Person> people, BFSD...
    method findPathBiBFS (line 51) | public static LinkedList<Person> findPathBiBFS(HashMap<Integer, Person...
    method main (line 71) | public static void main(String[] args) {

FILE: Java/Ch 09. Scalability and Memory Limits/Q9_02_Social_Network/Server.java
  class Server (line 5) | public class Server {
    method getMachineWithId (line 9) | public Machine getMachineWithId(int machineID) {
    method getMachineIDForUser (line 13) | public int getMachineIDForUser(int personID) {
    method getPersonWithID (line 18) | public Person getPersonWithID(int personID) {

FILE: Java/Ch 09. Scalability and Memory Limits/Q9_02_Social_Network/Tester.java
  class Tester (line 6) | public class Tester {
    method printPeople (line 8) | public static void printPeople(LinkedList<Person> path) {
    method isEqual (line 18) | public static boolean isEqual(LinkedList<Person> path1, LinkedList<Per...
    method isEquivalent (line 35) | public static boolean isEquivalent(LinkedList<Person> path1, LinkedLis...
    method main (line 41) | public static void main(String[] args) {

FILE: Java/Ch 09. Scalability and Memory Limits/Q9_05_Cache/Cache.java
  class Cache (line 5) | public class Cache {
    method Cache (line 12) | public Cache() {
    method moveToFront (line 16) | public void moveToFront(Node node) {
    method moveToFront (line 33) | public void moveToFront(String query) {
    method removeFromLinkedList (line 38) | public void removeFromLinkedList(Node node) {
    method getResults (line 69) | public String[] getResults(String query) {
    method insertResults (line 78) | public void insertResults(String query, String[] results) {

FILE: Java/Ch 09. Scalability and Memory Limits/Q9_05_Cache/Node.java
  class Node (line 3) | public class Node {
    method Node (line 9) | public Node(String q, String[] res) {

FILE: Java/Ch 09. Scalability and Memory Limits/Q9_05_Cache/Question.java
  class Question (line 3) | public class Question {
    method generateResults (line 5) | public static String[] generateResults(int i) {
    method main (line 10) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Introduction/BinarySearch.java
  class BinarySearch (line 3) | public class BinarySearch {
    method binarySearch (line 5) | public static int binarySearch(int[] a, int x) {
    method binarySearchRecursive (line 23) | public static int binarySearchRecursive(int[] a, int x, int low, int h...
    method binarySearchRecursiveClosest (line 37) | public static int binarySearchRecursiveClosest(int[] a, int x, int low...
    method main (line 57) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Introduction/MergeSort.java
  class MergeSort (line 5) | public class MergeSort {
    method mergesort (line 6) | public static void mergesort(int[] array) {
    method mergesort (line 11) | public static void mergesort(int[] array, int[] helper, int low, int h...
    method merge (line 20) | public static void merge(int[] array, int[] helper, int low, int middl...
    method main (line 52) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Introduction/Quicksort.java
  class Quicksort (line 5) | public class Quicksort {
    method swap (line 6) | public static void swap(int[] array, int i, int j) {
    method partition (line 12) | public static int partition(int[] arr, int left, int right) {
    method quickSort (line 36) | public static void quickSort(int[] arr, int left, int right) {
    method main (line 46) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_01_Sorted_Merge/Question.java
  class Question (line 5) | public class Question {
    method merge (line 14) | public static void merge(int[] a, int[] b, int countA, int countB) {
    method main (line 32) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_02_Group_Anagrams/AnagramComparator.java
  class AnagramComparator (line 6) | public class AnagramComparator implements Comparator<String> {
    method sortChars (line 7) | private String sortChars(String s) {
    method compare (line 13) | public int compare(String s1, String s2) {

FILE: Java/Ch 10. Sorting and Searching/Q10_02_Group_Anagrams/Question.java
  class Question (line 7) | public class Question {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_02_Group_Anagrams/QuestionB.java
  class QuestionB (line 9) | public class QuestionB {
    method sort (line 10) | public static void sort(String[] array) {
    method sortChars (line 30) | public static String sortChars(String s) {
    method main (line 36) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_03_Search_in_Rotated_Array/Question.java
  class Question (line 3) | public class Question {
    method search (line 5) | public static int search(int a[], int x) {
    method search (line 10) | public static int search(int a[], int left, int right, int x) {
    method main (line 50) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_04_Sorted_Search_No_Size/Arrayish/Listy.java
  class Listy (line 3) | public class Listy {
    method Listy (line 6) | public Listy(int[] arr) {
    method elementAt (line 10) | public int elementAt(int index) {

FILE: Java/Ch 10. Sorting and Searching/Q10_04_Sorted_Search_No_Size/Arrayish/Question.java
  class Question (line 3) | public class Question {
    method binarySearch (line 5) | public static int binarySearch(Listy list, int value, int low, int hig...
    method search (line 22) | public static int search(Listy list, int value) {
    method main (line 30) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_05_Sparse_Search/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method search (line 4) | public static int search(String[] strings, String str, int first, int ...
    method search (line 41) | public static int search(String[] strings, String str) {
    method main (line 48) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_05_Sparse_Search/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method searchI (line 4) | public static int searchI(String[] strings, String str, int first, int...
    method searchR (line 40) | public static int searchR(String[] strings, String str, int first, int...
    method search (line 77) | public static int search(String[] strings, String str) {
    method main (line 84) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_07_Missing_Int/QuestionA.java
  class QuestionA (line 8) | public class QuestionA {
    method findOpenNumber (line 12) | public static void findOpenNumber() throws FileNotFoundException {
    method main (line 35) | public static void main(String[] args)  throws IOException {

FILE: Java/Ch 10. Sorting and Searching/Q10_07_Missing_Int/QuestionB.java
  class QuestionB (line 6) | public class QuestionB {
    method findOpenNumber (line 8) | public static int findOpenNumber(String filename) throws FileNotFoundE...
    method getCountPerBlock (line 30) | public static int[] getCountPerBlock(String filename, int rangeSize) t...
    method findBlockWithMissing (line 44) | public static int findBlockWithMissing(int[] blocks, int rangeSize) {
    method getBitVectorForRange (line 54) | public static byte[] getBitVectorForRange(String filename, int blockIn...
    method findZero (line 75) | public static int findZero(byte b) {
    method findZero (line 86) | public static int findZero(byte[] bitVector) {
    method generateFile (line 96) | public static void generateFile(String filename, int max, int missing)...
    method main (line 111) | public static void main(String[] args) throws FileNotFoundException {

FILE: Java/Ch 10. Sorting and Searching/Q10_08_Find_Duplicates/BitSet.java
  class BitSet (line 3) | class BitSet {
    method BitSet (line 6) | public BitSet(int size) {
    method get (line 10) | boolean get(int pos) {
    method set (line 16) | void set(int pos) {

FILE: Java/Ch 10. Sorting and Searching/Q10_08_Find_Duplicates/Question.java
  class Question (line 5) | public class Question {
    method checkDuplicates (line 7) | public static void checkDuplicates(int[] array) {
    method main (line 20) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_09_Sorted_Matrix_Search/Coordinate.java
  class Coordinate (line 3) | public class Coordinate implements Cloneable {
    method Coordinate (line 6) | public Coordinate(int r, int c) {
    method inbounds (line 11) | public boolean inbounds(int[][] matrix) {
    method isBefore (line 18) | public boolean isBefore(Coordinate p) {
    method clone (line 22) | public Object clone() {
    method moveDownRight (line 26) | public void moveDownRight() {
    method setToAverage (line 31) | public void setToAverage(Coordinate min, Coordinate max) {

FILE: Java/Ch 10. Sorting and Searching/Q10_09_Sorted_Matrix_Search/QuestionA.java
  class QuestionA (line 4) | public class QuestionA {
    method findElement (line 6) | public static boolean findElement(int[][] matrix, int elem) {
    method main (line 21) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_09_Sorted_Matrix_Search/QuestionB.java
  class QuestionB (line 4) | public class QuestionB {
    method partitionAndSearch (line 6) | public static Coordinate partitionAndSearch(int[][] matrix, Coordinate...
    method findElement (line 19) | public static Coordinate findElement(int[][] matrix, Coordinate origin...
    method findElement (line 53) | public static Coordinate findElement(int[][] matrix, int x) {
    method main (line 59) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_10_Rank_from_Stream/IntComparable.java
  class IntComparable (line 5) | public class IntComparable implements Comparator<Integer>{
    method compare (line 7) | @Override

FILE: Java/Ch 10. Sorting and Searching/Q10_10_Rank_from_Stream/Question.java
  class Question (line 5) | public class Question {
    method track (line 8) | public static void track(int number) {
    method getRankOfNumber (line 16) | public static int getRankOfNumber(int number) {
    method main (line 20) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_10_Rank_from_Stream/RankNode.java
  class RankNode (line 3) | public class RankNode {
    method RankNode (line 8) | public RankNode(int d) {
    method insert (line 12) | public void insert(int d) {
    method getRank (line 29) | public int getRank(int d) {

FILE: Java/Ch 10. Sorting and Searching/Q10_11_Peaks_and_Valleys/QuestionA.java
  class QuestionA (line 7) | public class QuestionA {
    method sortValleyPeak (line 8) | public static void sortValleyPeak(int[] array) {
    method swap (line 15) | public static void swap(int[] array, int left, int right) {
    method main (line 21) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_11_Peaks_and_Valleys/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method swap (line 6) | public static void swap(int[] array, int left, int right) {
    method sortValleyPeak (line 12) | public static void sortValleyPeak(int[] array) {
    method maxIndex (line 21) | public static int maxIndex(int[] array, int a, int b, int c) {
    method main (line 38) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_11_Peaks_and_Valleys/QuestionC.java
  class QuestionC (line 5) | public class QuestionC {
    method swap (line 6) | public static void swap(int[] array, int left, int right) {
    method sortValleyPeak (line 12) | public static void sortValleyPeak(int[] array) {
    method main (line 23) | public static void main(String[] args) {

FILE: Java/Ch 10. Sorting and Searching/Q10_11_Peaks_and_Valleys/Tester.java
  class Tester (line 5) | public class Tester {
    method confirmValleyPeak (line 6) | public static boolean confirmValleyPeak(int[] array) {
    method main (line 22) | public static void main(String[] args) {

FILE: Java/Ch 13. Java/Introduction/Ambiguous.java
  class Ambiguous (line 3) | public class Ambiguous extends Shape {
    method computeArea (line 6) | public double computeArea() {

FILE: Java/Ch 13. Java/Introduction/Circle.java
  class Circle (line 3) | public class Circle extends Shape {
    method printMe (line 5) | public void printMe() {
    method computeArea (line 9) | public double computeArea() {

FILE: Java/Ch 13. Java/Introduction/Introduction.java
  class Introduction (line 3) | public class Introduction {
    method lem (line 4) | public static String lem() {
    method foo (line 9) | public static String foo() {
    method bar (line 26) | public static void bar() {
    method main (line 33) | public static void main(String[] args) {

FILE: Java/Ch 13. Java/Introduction/IntroductionCollections.java
  class IntroductionCollections (line 9) | public class IntroductionCollections {
    method main (line 10) | public static void main(String[] args) {

FILE: Java/Ch 13. Java/Introduction/IntroductionOverriding.java
  class IntroductionOverriding (line 3) | public class IntroductionOverriding {
    method printArea (line 5) | public static void printArea(Circle c) {
    method printArea (line 9) | public static void printArea(Square s) {
    method printArea (line 13) | public static void printArea(Ambiguous s) {
    method main (line 17) | public static void main(String[] args) {

FILE: Java/Ch 13. Java/Introduction/Shape.java
  class Shape (line 3) | public abstract class Shape {
    method printMe (line 4) | public void printMe() {
    method computeArea (line 8) | public abstract double computeArea();

FILE: Java/Ch 13. Java/Introduction/Square.java
  class Square (line 3) | public class Square extends Shape {
    method printMe (line 5) | public void printMe() {
    method computeArea (line 9) | public double computeArea() {

FILE: Java/Ch 13. Java/Q13_01_Private_Constructor/Question.java
  class Question (line 3) | public class Question {
    method Question (line 4) | private Question() {
    class A (line 8) | static class A {
      method A (line 9) | private A() {
    class B (line 13) | static class B extends A {
      method B (line 14) | public B() {
    method main (line 18) | public static void main(String[] args) {

FILE: Java/Ch 13. Java/Q13_05_TreeMap_HashMap_LinkedHashMap/Question.java
  class Question (line 8) | public class Question {
    method insertAndPrint (line 9) | public static void insertAndPrint(AbstractMap<Integer, String> map) {
    method main (line 20) | public static void main(String[] args) {

FILE: Java/Ch 13. Java/Q13_06_Object_Reflection/Question.java
  class Question (line 5) | public class Question {
    method main (line 6) | public static void main(String args[]) {

FILE: Java/Ch 13. Java/Q13_06_Object_Reflection/Rectangle.java
  class Rectangle (line 3) | public class Rectangle {
    method Rectangle (line 6) | public Rectangle(double w, double h) {
    method area (line 11) | public double area() {

FILE: Java/Ch 13. Java/Q13_07_Lambda_Expressions/Country.java
  class Country (line 3) | public class Country {
    method Country (line 7) | public Country(String n, String c, int sz) {
    method getName (line 13) | public String getName() {
    method getContinent (line 17) | public String getContinent() {
    method getPopulation (line 21) | public int getPopulation() {

FILE: Java/Ch 13. Java/Q13_07_Lambda_Expressions/QuestionA.java
  class QuestionA (line 6) | public class QuestionA {
    method getPopulation (line 8) | public static int getPopulation(List<Country> countries, String contin...
    method main (line 18) | public static void main(String... args) {

FILE: Java/Ch 13. Java/Q13_07_Lambda_Expressions/QuestionB.java
  class QuestionB (line 7) | public class QuestionB {
    method getPopulation (line 8) | public static int getPopulation(List<Country> countries, String contin...
    method main (line 18) | public static void main(String... args) {

FILE: Java/Ch 13. Java/Q13_07_Lambda_Expressions/QuestionC.java
  class QuestionC (line 7) | public class QuestionC {
    method getPopulation (line 8) | public static int getPopulation(List<Country> countries, String contin...
    method main (line 14) | public static void main(String... args) {

FILE: Java/Ch 13. Java/Q13_07_Lambda_Expressions/Tester.java
  class Tester (line 5) | public class Tester {
    method main (line 7) | public static void main(String[] args) {

FILE: Java/Ch 13. Java/Q13_08_Lambda_Random/QuestionA.java
  class QuestionA (line 7) | public class QuestionA {
    method getRandomSubset (line 9) | public static List<Integer> getRandomSubset(List<Integer> list) {
    method main (line 20) | public static void main(String... args) {

FILE: Java/Ch 13. Java/Q13_08_Lambda_Random/QuestionB.java
  class QuestionB (line 8) | public class QuestionB {
    method getRandomSubset (line 9) | public static List<Integer> getRandomSubset(List<Integer> list) {
    method main (line 17) | public static void main(String... args) {

FILE: Java/Ch 13. Java/Q13_08_Lambda_Random/QuestionC.java
  class QuestionC (line 9) | public class QuestionC {
    method getRandomSubset (line 15) | public static List<Integer> getRandomSubset(List<Integer> list) {
    method main (line 21) | public static void main(String... args) {

FILE: Java/Ch 15. Threads and Locks/IntroductionA/ExampleA.java
  class ExampleA (line 3) | public class ExampleA {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 15. Threads and Locks/IntroductionA/RunnableThreadExample.java
  class RunnableThreadExample (line 3) | public class RunnableThreadExample implements Runnable {
    method run (line 6) | public void run() {

FILE: Java/Ch 15. Threads and Locks/IntroductionB/ExampleB.java
  class ExampleB (line 3) | public class ExampleB {
    method main (line 4) | public static void main(String args[]) {

FILE: Java/Ch 15. Threads and Locks/IntroductionB/ThreadExample.java
  class ThreadExample (line 3) | public class ThreadExample extends Thread {
    method run (line 6) | public void run() {

FILE: Java/Ch 15. Threads and Locks/IntroductionLocks/Intro.java
  class Intro (line 3) | public class Intro {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 15. Threads and Locks/IntroductionLocks/LockedATM.java
  class LockedATM (line 6) | public class LockedATM {
    method LockedATM (line 10) | public LockedATM() {
    method withdraw (line 14) | public int withdraw(int value) {
    method deposit (line 27) | public int deposit(int value) {
    method getBalance (line 40) | public int getBalance() {

FILE: Java/Ch 15. Threads and Locks/IntroductionLocks/MyClass.java
  class MyClass (line 8) | public class MyClass extends Thread  {
    method MyClass (line 15) | public MyClass(NoLockATM atm1, LockedATM atm2) {
    method run (line 21) | public void run() {
    method waitUntilDone (line 38) | public void waitUntilDone() {

FILE: Java/Ch 15. Threads and Locks/IntroductionLocks/NoLockATM.java
  class NoLockATM (line 3) | public class NoLockATM {
    method NoLockATM (line 6) | public NoLockATM() {
    method withdraw (line 9) | public int withdraw(int value) {
    method deposit (line 20) | public int deposit(int value) {
    method getBalance (line 31) | public int getBalance() {

FILE: Java/Ch 15. Threads and Locks/IntroductionSynchronization/Intro.java
  class Intro (line 3) | public class Intro {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 15. Threads and Locks/IntroductionSynchronization/MyClass.java
  class MyClass (line 3) | public class MyClass extends Thread  {
    method MyClass (line 7) | public MyClass(MyObject obj, String n) {
    method run (line 12) | public void run() {

FILE: Java/Ch 15. Threads and Locks/IntroductionSynchronization/MyObject.java
  class MyObject (line 3) | public class MyObject {
    method foo (line 4) | public static synchronized void foo(String name) {
    method bar (line 14) | public static synchronized void bar(String name) {

FILE: Java/Ch 15. Threads and Locks/IntroductionSynchronizedBlocks/Intro.java
  class Intro (line 3) | public class Intro {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 15. Threads and Locks/IntroductionSynchronizedBlocks/MyClass.java
  class MyClass (line 3) | public class MyClass extends Thread  {
    method MyClass (line 7) | public MyClass(MyObject obj, String n) {
    method run (line 12) | public void run() {

FILE: Java/Ch 15. Threads and Locks/IntroductionSynchronizedBlocks/MyObject.java
  class MyObject (line 3) | public class MyObject {
    method foo (line 4) | public void foo(String name) {

FILE: Java/Ch 15. Threads and Locks/IntroductionWaitNotify/Intro.java
  class Intro (line 3) | public class Intro {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 15. Threads and Locks/IntroductionWaitNotify/MyClass.java
  class MyClass (line 3) | public class MyClass extends Thread  {
    method MyClass (line 7) | public MyClass(MyObject obj, String n) {
    method run (line 12) | public void run() {

FILE: Java/Ch 15. Threads and Locks/IntroductionWaitNotify/MyObject.java
  class MyObject (line 3) | public class MyObject {
    method foo (line 4) | public void foo(String name) {

FILE: Java/Ch 15. Threads and Locks/Q15_03_Dining_Philosophers/QuestionA/Chopstick.java
  class Chopstick (line 6) | public class Chopstick {
    method Chopstick (line 9) | public Chopstick() {
    method pickUp (line 13) | public boolean pickUp() {
    method putDown (line 17) | public void putDown() {

FILE: Java/Ch 15. Threads and Locks/Q15_03_Dining_Philosophers/QuestionA/Philosopher.java
  class Philosopher (line 5) | public class Philosopher extends Thread {
    method Philosopher (line 12) | public Philosopher(int i, Chopstick left, Chopstick right) {
    method eat (line 18) | public void eat() {
    method pickUp (line 29) | public boolean pickUp() {
    method chew (line 43) | public void chew() {
    method pause (line 48) | public void pause() {
    method putDown (line 57) | public void putDown() {
    method run (line 62) | public void run() {

FILE: Java/Ch 15. Threads and Locks/Q15_03_Dining_Philosophers/QuestionA/Question.java
  class Question (line 3) | public class Question {
    method leftOf (line 6) | public static int leftOf(int i) {
    method rightOf (line 10) | public static int rightOf(int i) {
    method main (line 14) | public static void main(String[] args) {

FILE: Java/Ch 15. Threads and Locks/Q15_03_Dining_Philosophers/QuestionB/Chopstick.java
  class Chopstick (line 6) | public class Chopstick {
    method Chopstick (line 10) | public Chopstick(int n) {
    method pickUp (line 15) | public void pickUp() {
    method putDown (line 19) | public void putDown() {
    method getNumber (line 23) | public int getNumber() {

FILE: Java/Ch 15. Threads and Locks/Q15_03_Dining_Philosophers/QuestionB/Philosopher.java
  class Philosopher (line 5) | public class Philosopher extends Thread {
    method Philosopher (line 12) | public Philosopher(int i, Chopstick left, Chopstick right) {
    method eat (line 23) | public void eat() {
    method pickUp (line 31) | public void pickUp() {
    method chew (line 39) | public void chew() {
    method pause (line 44) | public void pause() {
    method putDown (line 53) | public void putDown() {
    method run (line 58) | public void run() {

FILE: Java/Ch 15. Threads and Locks/Q15_03_Dining_Philosophers/QuestionB/Question.java
  class Question (line 3) | public class Question {
    method leftOf (line 6) | public static int leftOf(int i) {
    method rightOf (line 10) | public static int rightOf(int i) {
    method main (line 14) | public static void main(String[] args) {

FILE: Java/Ch 15. Threads and Locks/Q15_04_Deadlock_Free_Class/LockFactory.java
  class LockFactory (line 7) | public class LockFactory {
    method LockFactory (line 16) | private LockFactory(int count) {
    method getInstance (line 25) | public static LockFactory getInstance() {
    method initialize (line 29) | public static LockFactory initialize(int count) {
    method hasCycle (line 36) | public boolean hasCycle(HashMap<Integer, Boolean> touchedNodes, int[] ...
    method declare (line 52) | public boolean declare(int ownerId, int[] resourcesInOrder) {
    method getLock (line 89) | public Lock getLock(int ownerId, int resourceID) {

FILE: Java/Ch 15. Threads and Locks/Q15_04_Deadlock_Free_Class/LockNode.java
  class LockNode (line 8) | public class LockNode {
    type VisitState (line 9) | public enum VisitState {
    method LockNode (line 18) | public LockNode(int id, int max) {
    method joinTo (line 25) | public void joinTo(LockNode node) {
    method remove (line 29) | public void remove(LockNode node) {
    method hasCycle (line 34) | public boolean hasCycle(HashMap<Integer, Boolean> touchedNodes) {
    method hasCycle (line 42) | private boolean hasCycle(VisitState[] visited, HashMap<Integer, Boolea...
    method getLock (line 61) | public Lock getLock() {
    method getId (line 68) | public int getId() {

FILE: Java/Ch 15. Threads and Locks/Q15_04_Deadlock_Free_Class/Question.java
  class Question (line 3) | public class Question {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 15. Threads and Locks/Q15_05_Call_In_Order/Foo.java
  class Foo (line 5) | public class Foo {
    method Foo (line 10) | public Foo() {
    method first (line 22) | public void first() {
    method second (line 33) | public void second() {
    method third (line 46) | public void third() {

FILE: Java/Ch 15. Threads and Locks/Q15_05_Call_In_Order/FooBad.java
  class FooBad (line 5) | public class FooBad {
    method FooBad (line 10) | public FooBad() {
    method first (line 22) | public void first() {
    method second (line 33) | public void second() {
    method third (line 46) | public void third() {

FILE: Java/Ch 15. Threads and Locks/Q15_05_Call_In_Order/MyThread.java
  class MyThread (line 3) | public class MyThread extends Thread {
    method MyThread (line 7) | public MyThread(FooBad foo, String method) {
    method run (line 12) | public void run() {

FILE: Java/Ch 15. Threads and Locks/Q15_05_Call_In_Order/Question.java
  class Question (line 3) | public class Question {
    method main (line 4) | public static void main(String[] args) {

FILE: Java/Ch 15. Threads and Locks/Q15_06_Synchronized_Methods/Foo.java
  class Foo (line 3) | public class Foo {
    method Foo (line 6) | public Foo(String nm) {
    method getName (line 10) | public String getName() {
    method pause (line 14) | public void pause() {
    method methodA (line 22) | public synchronized void methodA(String threadName) {
    method methodB (line 28) | public void methodB(String threadName) {

FILE: Java/Ch 15. Threads and Locks/Q15_06_Synchronized_Methods/MyThread.java
  class MyThread (line 3) | public class MyThread extends Thread {
    method MyThread (line 7) | public MyThread(Foo f, String nm, String fM) {
    method run (line 13) | public void run() {

FILE: Java/Ch 15. Threads and Locks/Q15_06_Synchronized_Methods/Question.java
  class Question (line 3) | public class Question {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 15. Threads and Locks/Q15_07_FizzBuzz/FBThread.java
  class FBThread (line 6) | public class FBThread extends Thread {
    method FBThread (line 14) | public FBThread(Predicate<Integer> validate, Function<Integer, String>...
    method run (line 20) | public void run() {

FILE: Java/Ch 15. Threads and Locks/Q15_07_FizzBuzz/FizzBuzzThread.java
  class FizzBuzzThread (line 3) | public class FizzBuzzThread extends Thread {
    method FizzBuzzThread (line 10) | public FizzBuzzThread(boolean div3, boolean div5, int max, String toPr...
    method print (line 17) | public void print() {
    method run (line 21) | public void run() {

FILE: Java/Ch 15. Threads and Locks/Q15_07_FizzBuzz/NumberThread.java
  class NumberThread (line 3) | public class NumberThread extends FizzBuzzThread {
    method NumberThread (line 4) | public NumberThread(boolean div3, boolean div5, int max) {
    method print (line 8) | public void print() {

FILE: Java/Ch 15. Threads and Locks/Q15_07_FizzBuzz/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method fizzbuzz (line 5) | public static void fizzbuzz(int n) {
    method main (line 19) | public static void main(String[] args) {

FILE: Java/Ch 15. Threads and Locks/Q15_07_FizzBuzz/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 15. Threads and Locks/Q15_07_FizzBuzz/QuestionC.java
  class QuestionC (line 3) | public class QuestionC {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_01_Number_Swapper/Question.java
  class Question (line 3) | public class Question {
    method swap (line 5) | public static void swap(int a, int b) {
    method swap_opt (line 15) | public static void swap_opt(int a, int b) {
    method main (line 24) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_02_Word_Frequencies/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method getFrequency (line 6) | public static int getFrequency(String[] book, String word) {
    method main (line 17) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_02_Word_Frequencies/QuestionB.java
  class QuestionB (line 7) | public class QuestionB {
    method setupDictionary (line 8) | public static HashMap<String, Integer> setupDictionary(String[] book) {
    method getFrequency (line 21) | public static int getFrequency(HashMap<String, Integer> table, String ...
    method main (line 32) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_03_Intersection/Line.java
  class Line (line 4) | public class Line {
    method Line (line 8) | public Line(Point start, Point end) {
    method isVertical (line 20) | public boolean isVertical() {
    method toString (line 24) | @Override
    method getYFromX (line 29) | public double getYFromX(double x) {

FILE: Java/Ch 16. Moderate/Q16_03_Intersection/Point.java
  class Point (line 3) | public class Point {
    method Point (line 5) | public Point(double x, double y) {
    method toString (line 10) | @Override

FILE: Java/Ch 16. Moderate/Q16_03_Intersection/Question.java
  class Question (line 3) | public class Question {
    method isBetween (line 6) | public static boolean isBetween(double start, double middle, double en...
    method isBetween (line 15) | public static boolean isBetween(Point start, Point middle, Point end) {
    method intersection (line 19) | public static Point intersection(Point start1, Point end1, Point start...
    method main (line 66) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_03_Intersection/Tester.java
  class Tester (line 5) | public class Tester {
    method equalish (line 7) | public static boolean equalish(double a, double b) {
    method checkIfPointOnLineSegments (line 11) | public static boolean checkIfPointOnLineSegments(Point start, Point mi...
    method getPoints (line 33) | public static ArrayList<Point> getPoints(int size) {
    method runTest (line 43) | public static boolean runTest(Point start1, Point end1, Point start2, ...
    method main (line 74) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_04_Tic_Tac_Win/Piece.java
  type Piece (line 3) | enum Piece { Empty, Red, Blue }

FILE: Java/Ch 16. Moderate/Q16_04_Tic_Tac_Win/Position.java
  class Position (line 3) | public class Position {
    method Position (line 5) | public Position(int row, int column) {

FILE: Java/Ch 16. Moderate/Q16_04_Tic_Tac_Win/PositionIterator.java
  class PositionIterator (line 5) | public class PositionIterator implements Iterator<Position> {
    method PositionIterator (line 9) | public PositionIterator(Position p, int rowIncrement, int colIncrement...
    method hasNext (line 16) | @Override
    method next (line 21) | @Override

FILE: Java/Ch 16. Moderate/Q16_04_Tic_Tac_Win/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method convertBoardToInt (line 5) | public static int convertBoardToInt(Piece[][] board) {
    method main (line 16) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_04_Tic_Tac_Win/QuestionB.java
  class QuestionB (line 6) | public class QuestionB {
    method hasWon (line 7) | public static Piece hasWon(Piece[][] board, int row, int column) {
    method hasWonRow (line 28) | public static boolean hasWonRow(Piece[][] board, int row) {
    method hasWonColumn (line 37) | public static boolean hasWonColumn(Piece[][] board, int column) {
    method hasWonDiagonal (line 46) | public static boolean hasWonDiagonal(Piece[][] board, int direction) {
    method main (line 60) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_04_Tic_Tac_Win/QuestionC.java
  class QuestionC (line 5) | public class QuestionC {
    method hasWinner (line 6) | public static boolean hasWinner(Piece p1, Piece p2, Piece p3) {
    method hasWon (line 13) | public static Piece hasWon(Piece[][] board) {
    method main (line 38) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_04_Tic_Tac_Win/QuestionD.java
  class QuestionD (line 5) | public class QuestionD {
    method hasWinner (line 6) | public static boolean hasWinner(Piece p1, Piece p2, Piece p3) {
    method hasWon (line 13) | public static Piece hasWon(Piece[][] board) {
    method main (line 37) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_04_Tic_Tac_Win/QuestionE.java
  class QuestionE (line 5) | public class QuestionE {
    method hasWon (line 7) | public static Piece hasWon(Piece[][] board) {
    method main (line 64) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_04_Tic_Tac_Win/QuestionF.java
  class QuestionF (line 5) | public class QuestionF {
    method hasWon (line 7) | public static Piece hasWon(Piece[][] board) {
    method hasWon (line 36) | public static Piece hasWon(Piece[][] board, int row, int col, int incr...
    method main (line 48) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_04_Tic_Tac_Win/QuestionG.java
  class QuestionG (line 7) | public class QuestionG {
    class Check (line 8) | public static class Check {
      method Check (line 11) | public Check(int row, int column, int rowI, int colI) {
      method increment (line 18) | public void increment() {
      method inBounds (line 23) | public boolean inBounds(int size) {
    method hasWon (line 29) | public static Piece hasWon(Piece[][] board) {
    method hasWon (line 52) | public static Piece hasWon(Piece[][] board, Check instr) {
    method main (line 63) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_04_Tic_Tac_Win/QuestionH.java
  class QuestionH (line 7) | public class QuestionH {
    method hasWon (line 8) | public static Piece hasWon(Piece[][] board) {
    method hasWon (line 29) | public static Piece hasWon(Piece[][] board, PositionIterator iterator) {
    method main (line 41) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_04_Tic_Tac_Win/Tester.java
  class Tester (line 5) | public class Tester {
    method convertIntToPiece (line 6) | public static Piece convertIntToPiece(int i) {
    method hasWonB (line 19) | public static Piece hasWonB(Piece[][] board) {
    method main (line 31) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_05_Factorial_Zeros/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method factorsOf5 (line 4) | public static int factorsOf5(int i) {
    method countFactZeros (line 13) | public static int countFactZeros(int num) {
    method factorial (line 21) | public static int factorial(int num) {
    method main (line 31) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_05_Factorial_Zeros/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method countFactZeros (line 4) | public static int countFactZeros(int num) {
    method factorial (line 16) | public static int factorial(int num) {
    method main (line 26) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_06_Smallest_Difference/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method findSmallestDifference (line 4) | public static int findSmallestDifference(int[] arrayA, int[] arrayB) {
    method main (line 16) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_06_Smallest_Difference/QuestionB.java
  class QuestionB (line 4) | public class QuestionB {
    method findSmallestDifference (line 5) | public static int findSmallestDifference(int[] arrayA, int[] arrayB) {
    method main (line 25) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_06_Smallest_Difference/QuestionC.java
  class QuestionC (line 4) | public class QuestionC {
    method getClosestValue (line 5) | public static int getClosestValue(int[] array, int target) {
    method findSmallestDifference (line 26) | public static int findSmallestDifference(int[] shorter, int[] longer) {
    method main (line 41) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_06_Smallest_Difference/Tester.java
  class Tester (line 5) | public class Tester {
    method main (line 6) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_07_Number_Max/Question.java
  class Question (line 3) | public class Question {
    method flip (line 5) | public static int flip(int bit) {
    method sign (line 10) | public static int sign(int a) {
    method getMaxNaive (line 14) | public static int getMaxNaive(int a, int b) {
    method getMax (line 20) | public static int getMax(int a, int b) {
    method main (line 40) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_08_English_Int/Question.java
  class Question (line 7) | public class Question {
    method convert (line 14) | public static String convert(int num) {
    method listToString (line 37) | public static String listToString(LinkedList<String> parts) {
    method convertChunk (line 47) | public static String convertChunk(int number) {
    method main (line 73) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_09_Operations/Question.java
  class Question (line 7) | public class Question {
    method negate (line 9) | public static int negate(int a) {
    method negateOptimized (line 20) | public static int negateOptimized(int a) {
    method minus (line 37) | public static int minus(int a, int b) {
    method abs (line 42) | public static int abs(int a) {
    method multiply (line 50) | public static int multiply(int a, int b) {
    method divide (line 66) | public static int divide(int a, int b) throws java.lang.ArithmeticExce...
    method main (line 87) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_10_Living_People/Person.java
  class Person (line 3) | public class Person {
    method Person (line 6) | public Person(int birthYear, int deathYear) {

FILE: Java/Ch 16. Moderate/Q16_10_Living_People/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method maxAliveYear (line 7) | public static int maxAliveYear(Person[] people, int min, int max) {
    method main (line 27) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_10_Living_People/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method maxAliveYear (line 7) | public static int maxAliveYear(Person[] people, int min, int max) {
    method createYearMap (line 15) | public static int[] createYearMap(Person[] people, int min, int max) {
    method incrementRange (line 26) | public static void incrementRange(int[] values, int left, int right) {
    method getMaxIndex (line 33) | public static int getMaxIndex(int[] values) {
    method main (line 43) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_10_Living_People/QuestionC.java
  class QuestionC (line 6) | public class QuestionC {
    method maxAliveYear (line 7) | public static int maxAliveYear(Person[] people, int min, int max) {
    method getSortedYears (line 37) | public static int[] getSortedYears(Person[] people, boolean copyBirthY...
    method main (line 46) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_10_Living_People/QuestionD.java
  class QuestionD (line 5) | public class QuestionD {
    method maxAliveYear (line 7) | public static int maxAliveYear(Person[] people, int min, int max) {
    method getPopulationDeltas (line 15) | public static int[] getPopulationDeltas(Person[] people, int min, int ...
    method getMaxAliveYear (line 28) | public static int getMaxAliveYear(int[] deltas) {
    method main (line 43) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_10_Living_People/Tester.java
  class Tester (line 5) | public class Tester {
    method main (line 9) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_11_Diving_Board/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method allLengths (line 8) | public static HashSet<Integer> allLengths(int k, int shorter, int long...
    method getAllLengths (line 14) | public static void getAllLengths(int k, int total, int shorter, int lo...
    method main (line 24) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_11_Diving_Board/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method allLengths (line 8) | public static HashSet<Integer> allLengths(int k, int shorter, int long...
    method getAllLengths (line 15) | public static void getAllLengths(int k, int total, int shorter, int lo...
    method main (line 30) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_11_Diving_Board/QuestionC.java
  class QuestionC (line 5) | public class QuestionC {
    method allLengths (line 8) | public static HashSet<Integer> allLengths(int k, int shorter, int long...
    method main (line 19) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_11_Diving_Board/Tester.java
  class Tester (line 5) | public class Tester {
    method main (line 7) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_12_XML_Encoding/Attribute.java
  class Attribute (line 3) | public class Attribute {
    method Attribute (line 6) | public Attribute(String t, String v) {
    method getTagCode (line 11) | public String getTagCode() {

FILE: Java/Ch 16. Moderate/Q16_12_XML_Encoding/Element.java
  class Element (line 5) | public class Element {
    method Element (line 11) | public Element(String n) {
    method Element (line 17) | public Element(String n, String v) {
    method getNameCode (line 24) | public String getNameCode() {
    method insert (line 39) | public void insert(Attribute attribute) {
    method insert (line 43) | public void insert(Element child) {

FILE: Java/Ch 16. Moderate/Q16_12_XML_Encoding/QuestionOO.java
  class QuestionOO (line 4) | public class QuestionOO {
    method encode (line 6) | public static void encode(String v, StringBuilder sb) {
    method encodeEnd (line 12) | public static void encodeEnd(StringBuilder sb) {
    method encode (line 17) | public static void encode(Attribute attr, StringBuilder sb) {
    method encode (line 22) | public static void encode(Element root, StringBuilder sb) {
    method encodeToString (line 38) | public static String encodeToString(Element root) {
    method main (line 44) | public static void main(String args[]) {

FILE: Java/Ch 16. Moderate/Q16_12_XML_Encoding/QuestionString.java
  class QuestionString (line 9) | public class QuestionString {
    method QuestionString (line 16) | public QuestionString(Map<String, Byte> tagMap) {this.tagMap = tagMap;}
    method encode (line 18) | public byte[] encode(char[] input) throws IOException {
    method encodeTokens (line 29) | private void encodeTokens(ByteArrayOutputStream output)
    method nextToken (line 78) | private String nextToken() throws IOException {
    method nextToken (line 88) | private void nextToken(String expectedToken) throws IOException {
    method hasNextToken (line 102) | private boolean hasNextToken(String expectedToken) {
    method hasNextTokens (line 110) | private boolean hasNextTokens(String... expectedTokens) {
    method tokenize (line 123) | private void tokenize(char[] input) {
    method setNextToken (line 131) | private int setNextToken(char[] input, int inputIndex) {
    method getTagCode (line 158) | private byte getTagCode(String tag) throws IOException {
    method main (line 166) | public static void main(String args[]) {
    method print (line 196) | public static void print(byte[] output) {

FILE: Java/Ch 16. Moderate/Q16_13_Bisect_Squares/Line.java
  class Line (line 3) | public class Line {
    method Line (line 6) | public Line(Point start, Point end) {
    method toString (line 11) | public String toString() {

FILE: Java/Ch 16. Moderate/Q16_13_Bisect_Squares/Point.java
  class Point (line 3) | public class Point {
    method Point (line 6) | public Point(double x, double y) {
    method isEqual (line 11) | public boolean isEqual(Point p) {
    method toString (line 15) | public String toString() {

FILE: Java/Ch 16. Moderate/Q16_13_Bisect_Squares/Question.java
  class Question (line 3) | public class Question {
    method randomInt (line 5) | public static int randomInt(int n) {
    method printLine (line 9) | public static void printLine(Line l) {
    method printSquare (line 14) | public static void printSquare(Square s) {
    method isApproxEqual (line 18) | public static boolean isApproxEqual(double d1, double d2) {
    method isApproxEqual (line 26) | public static boolean isApproxEqual(Point p1, Point p2) {
    method doTest (line 30) | public static boolean doTest(Square s1, Square s2, Point start, Point ...
    method doTestFull (line 45) | public static boolean doTestFull(Square s1, Square s2, Point start, Po...
    method doTests (line 49) | public static void doTests() {
    method main (line 75) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_13_Bisect_Squares/Square.java
  class Square (line 3) | public class Square {
    method Square (line 9) | public Square(double left, double top, double size) {
    method middle (line 17) | public Point middle() {
    method contains (line 21) | public boolean contains(Square other) {
    method extend (line 32) | public Point extend(Point mid1, Point mid2, double size) {
    method cut (line 66) | public Line cut(Square other) {
    method toString (line 89) | public String toString() {

FILE: Java/Ch 16. Moderate/Q16_14_Best_Line/GraphPoint.java
  class GraphPoint (line 3) | public class GraphPoint {
    method GraphPoint (line 6) | public GraphPoint(double x1, double y1) {
    method toString (line 11) | public String toString() {

FILE: Java/Ch 16. Moderate/Q16_14_Best_Line/Line.java
  class Line (line 3) | public class Line {
    method Line (line 10) | public Line(GraphPoint p, GraphPoint q) {
    method isEquivalent (line 20) | public boolean isEquivalent(double a, double b) {
    method Print (line 24) | public void Print() {
    method floorToNearestEpsilon (line 28) | public static double floorToNearestEpsilon(double d) {
    method isEquivalent (line 33) | public boolean isEquivalent(Object o) {

FILE: Java/Ch 16. Moderate/Q16_14_Best_Line/Question.java
  class Question (line 9) | public class Question {
    method findBestLine (line 11) | public static Line findBestLine(GraphPoint[] points) {
    method getListOfLines (line 17) | public static HashMapList<Double, Line> getListOfLines(GraphPoint[] po...
    method getBestLine (line 30) | public static Line getBestLine(HashMapList<Double, Line> linesBySlope) {
    method countEquivalentLines (line 57) | public static int countEquivalentLines(HashMapList<Double, Line> lines...
    method countEquivalentLines (line 66) | public static int countEquivalentLines(ArrayList<Line> lines, Line lin...
    method createPoints (line 82) | public static GraphPoint[] createPoints() {
    method validate (line 100) | public static int validate(Line line, GraphPoint[] points) {
    method main (line 113) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_15_Master_Mind/Question.java
  class Question (line 3) | public class Question {
    method code (line 4) | public static int code(char c) {
    method letterFromCode (line 19) | public static char letterFromCode(int k) {
    method estimate (line 36) | public static Result estimate(String guess, String solution) {
    method main (line 67) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_15_Master_Mind/Result.java
  class Result (line 3) | public class Result {
    method Result (line 7) | public Result(int h, int p) {
    method toString (line 12) | @Override

FILE: Java/Ch 16. Moderate/Q16_15_Master_Mind/Tester.java
  class Tester (line 5) | public class Tester {
    method estimateBad (line 7) | public static Result estimateBad(String g, String s) {
    method randomString (line 38) | public static String randomString() {
    method test (line 52) | public static boolean test(String guess, String solution) {
    method testRandom (line 63) | public static boolean testRandom() {
    method test (line 69) | public static boolean test(int count) {
    method main (line 79) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_16_Sub_Sort/Question.java
  class Question (line 3) | public class Question {
    method findEndOfLeftSubsequence (line 5) | public static int findEndOfLeftSubsequence(int[] array) {
    method findStartOfRightSubsequence (line 14) | public static int findStartOfRightSubsequence(int[] array) {
    method shrinkLeft (line 23) | public static int shrinkLeft(int[] array, int min_index, int start) {
    method shrinkRight (line 33) | public static int shrinkRight(int[] array, int max_index, int start) {
    method findUnsortedSequence (line 43) | public static Range findUnsortedSequence(int[] array) {
    method validate (line 78) | public static boolean validate(int[] array, int left_index, int right_...
    method main (line 95) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_16_Sub_Sort/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method findRightSequenceStart (line 5) | public static int findRightSequenceStart(int[] array) {
    method findLeftSequenceEnd (line 17) | public static int findLeftSequenceEnd(int[] array) {
    method findUnsortedSequence (line 29) | public static Range findUnsortedSequence(int[] array) {
    method main (line 35) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_16_Sub_Sort/Range.java
  class Range (line 3) | public class Range {
    method Range (line 5) | public Range(int start, int end) {
    method toString (line 10) | @Override
    method hashCode (line 15) | @Override
    method equals (line 24) | @Override

FILE: Java/Ch 16. Moderate/Q16_16_Sub_Sort/Tester.java
  class Tester (line 5) | public class Tester {
    method main (line 7) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_17_Contiguous_Sequence/Question.java
  class Question (line 3) | public class Question {
    method getMaxSum (line 5) | public static int getMaxSum(int[] a) {
    method main (line 19) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_18_Pattern_Matcher/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method doesMatch (line 6) | public static boolean doesMatch(String pattern, String value) {
    method buildFromPattern (line 26) | public static String buildFromPattern(String pattern, String main, Str...
    method main (line 39) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_18_Pattern_Matcher/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method formStringFromPattern (line 5) | public static String formStringFromPattern(String pattern, String firs...
    method countOf (line 22) | public static int countOf(String pattern, char ch) {
    method canonical (line 32) | public static String canonical(String pattern) {
    method doesMatch (line 45) | public static boolean doesMatch(String pattern, String value) {
    method main (line 73) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_18_Pattern_Matcher/QuestionC.java
  class QuestionC (line 3) | public class QuestionC {
    method buildFromPattern (line 5) | public static String buildFromPattern(String pattern, String main, Str...
    method countOf (line 18) | public static int countOf(String pattern, char c) {
    method doesMatch (line 28) | public static boolean doesMatch(String pattern, String value) {
    method main (line 59) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_18_Pattern_Matcher/QuestionD.java
  class QuestionD (line 3) | public class QuestionD {
    method doesMatch (line 4) | public static boolean doesMatch(String pattern, String value) {
    method matches (line 29) | public static boolean matches(String pattern, String value, int mainSi...
    method isEqual (line 42) | public static boolean isEqual(String s1, int offset1, int offset2, int...
    method countOf (line 51) | public static int countOf(String pattern, char c) {
    method main (line 63) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_18_Pattern_Matcher/Tester.java
  class Tester (line 3) | public class Tester {
    method invert (line 4) | public static String invert(String pattern) {
    method main (line 16) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_19_Pond_Sizes/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method computePondSizes (line 6) | public static ArrayList<Integer> computePondSizes(int[][] land) {
    method computeSize (line 19) | public static int computeSize(int[][] land, int row, int col) {
    method main (line 34) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_19_Pond_Sizes/QuestionB.java
  class QuestionB (line 5) | public class QuestionB {
    method computePondSizes (line 7) | public static ArrayList<Integer> computePondSizes(int[][] land) {
    method computeSize (line 21) | public static int computeSize(int[][] land, boolean[][] visited, int r...
    method main (line 36) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_20_T9/QuestionA.java
  class QuestionA (line 9) | public class QuestionA {
    method getT9Chars (line 23) | public static char[] getT9Chars(char digit) {
    method getValidWords (line 31) | public static void getValidWords(String number, int index, String pref...
    method getValidT9Words (line 52) | public static ArrayList<String> getValidT9Words(String number, HashSet...
    method main (line 58) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_20_T9/QuestionB.java
  class QuestionB (line 10) | public class QuestionB {
    method getT9Chars (line 24) | public static char[] getT9Chars(char digit) {
    method getValidWords (line 32) | public static void getValidWords(String number, int index, String pref...
    method getValidT9Words (line 56) | public static ArrayList<String> getValidT9Words(String number, Trie tr...
    method main (line 62) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_20_T9/QuestionC.java
  class QuestionC (line 9) | public class QuestionC {
    method convertToT9 (line 25) | public static String convertToT9(String word, HashMap<Character, Chara...
    method createLetterToNumberMap (line 37) | public static HashMap<Character, Character> createLetterToNumberMap() {
    method initializeDictionary (line 53) | public static HashMapList<String, String> initializeDictionary(String[...
    method getValidT9Words (line 66) | public static ArrayList<String> getValidT9Words(String numbers, HashMa...
    method main (line 70) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_21_Sum_Swap/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method sum (line 5) | public static int sum(int[] array) {
    method findSwapValues (line 13) | public static int[] findSwapValues(int[] array1, int[] array2) {
    method main (line 31) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_21_Sum_Swap/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method findSwapValues (line 4) | public static int[] findSwapValues(int[] array1, int[] array2) {
    method getTarget (line 20) | public static Integer getTarget(int[] array1, int[] array2) {
    method sum (line 29) | public static int sum(int[] array) {
    method main (line 41) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_21_Sum_Swap/QuestionC.java
  class QuestionC (line 5) | public class QuestionC {
    method sum (line 7) | public static int sum(int[] array) {
    method findSwapValues (line 15) | public static int[] findSwapValues(int[] array1, int[] array2) {
    method findDifference (line 21) | public static int[] findDifference(int[] array1, int[] array2, int tar...
    method getTarget (line 34) | public static Integer getTarget(int[] array1, int[] array2) {
    method getContents (line 42) | public static HashSet<Integer> getContents(int[] array) {
    method main (line 50) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_21_Sum_Swap/QuestionD.java
  class QuestionD (line 6) | public class QuestionD {
    method sum (line 8) | public static int sum(int[] array) {
    method getTarget (line 16) | public static Integer getTarget(int[] array1, int[] array2) {
    method findSwapValues (line 24) | public static int[] findSwapValues(int[] array1, int[] array2) {
    method findDifference (line 30) | public static int[] findDifference(int[] array1, int[] array2, int tar...
    method main (line 56) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_21_Sum_Swap/Tester.java
  class Tester (line 5) | public class Tester {
    method isEquivalent (line 7) | public static boolean isEquivalent(int[] a, int[] b, int[] c, int[] d) {
    method difference (line 14) | public static int difference(int[] a) {
    method arrayToString (line 21) | public static String arrayToString(int[] array) {
    method main (line 29) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_22_Langtons_Ant/Ant.java
  class Ant (line 3) | public class Ant {
    method turn (line 7) | public void turn(boolean clockwise) {
    method move (line 11) | public void move() {
    method adjustPosition (line 23) | public void adjustPosition(int shiftRow, int shiftColumn) {

FILE: Java/Ch 16. Moderate/Q16_22_Langtons_Ant/Board.java
  class Board (line 5) | public class Board {
    method Board (line 11) | public Board() { }
    method move (line 14) | public void move() {
    method flip (line 22) | private void flip(Position position) {
    method ensureFit (line 32) | private void ensureFit(Position position) {
    method isBlack (line 44) | public boolean isBlack(Position p) {
    method isBlack (line 49) | public boolean isBlack(int row, int column) {
    method toString (line 54) | public String toString() {

FILE: Java/Ch 16. Moderate/Q16_22_Langtons_Ant/Grid.java
  class Grid (line 3) | public class Grid {
    method Grid (line 7) | public Grid() {
    method copyWithShift (line 12) | private void copyWithShift(boolean[][] oldGrid, boolean[][] newGrid, i...
    method ensureFit (line 25) | private void ensureFit(Position position) {
    method flip (line 57) | private void flip(Position position) {
    method move (line 64) | public void move() {
    method toString (line 81) | public String toString() {

FILE: Java/Ch 16. Moderate/Q16_22_Langtons_Ant/Orientation.java
  type Orientation (line 3) | public enum Orientation {
    method getTurn (line 6) | public Orientation getTurn(boolean clockwise) {
    method toString (line 18) | @Override

FILE: Java/Ch 16. Moderate/Q16_22_Langtons_Ant/Position.java
  class Position (line 3) | public class Position {
    method Position (line 7) | public Position(int row, int column) {
    method equals (line 12) | @Override
    method hashCode (line 21) | @Override
    method clone (line 26) | public Position clone() {

FILE: Java/Ch 16. Moderate/Q16_22_Langtons_Ant/Question.java
  class Question (line 3) | public class Question {
    method main (line 5) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_23_Rand7_From_Rand5/Question.java
  class Question (line 3) | public class Question {
    method rand7 (line 4) | public static int rand7() {
    method rand5 (line 13) | public static int rand5() {
    method main (line 17) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_23_Rand7_From_Rand5/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method rand7 (line 4) | public static int rand7() {
    method rand5 (line 19) | public static int rand5() {
    method main (line 23) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_24_Pairs_With_Sum/Pair.java
  class Pair (line 3) | public class Pair {
    method Pair (line 7) | public Pair(int first, int second) {
    method toString (line 12) | @Override

FILE: Java/Ch 16. Moderate/Q16_24_Pairs_With_Sum/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method printPairSums (line 6) | public static ArrayList<Pair> printPairSums(int[] array, int sum) {
    method main (line 18) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_24_Pairs_With_Sum/QuestionB.java
  class QuestionB (line 7) | public class QuestionB {
    method printPairSums (line 8) | public static ArrayList<Pair> printPairSums(int[] array, int sum) {
    method adjustCounterBy (line 23) | public static void adjustCounterBy(HashMap<Integer, Integer> counter, ...
    method main (line 28) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_24_Pairs_With_Sum/QuestionC.java
  class QuestionC (line 6) | public class QuestionC {
    method printPairSums (line 7) | public static ArrayList<Pair> printPairSums(int[] array, int sum) {
    method main (line 29) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_24_Pairs_With_Sum/Tester.java
  class Tester (line 7) | public class Tester {
    method print (line 9) | public static void print(ArrayList<Pair> pairs) {
    method main (line 16) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_25_LRU_Cache/Cache.java
  class Cache (line 5) | public class Cache {
    method Cache (line 12) | public Cache(int maxSize) {
    method getValue (line 17) | public String getValue(int key) {
    method removeFromLinkedList (line 32) | private void removeFromLinkedList(LinkedListNode node) {
    method insertAtFrontOfLinkedList (line 51) | private void insertAtFrontOfLinkedList(LinkedListNode node) {
    method removeKey (line 65) | public boolean removeKey(int key) {
    method setKeyValue (line 74) | public void setKeyValue(int key, String value) {
    method getCacheAsString (line 89) | public String getCacheAsString() {
    class LinkedListNode (line 94) | private class LinkedListNode {
      method LinkedListNode (line 99) | public LinkedListNode(int k, String v) {
      method printForward (line 104) | public String printForward() {

FILE: Java/Ch 16. Moderate/Q16_25_LRU_Cache/Question.java
  class Question (line 3) | public class Question {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_26_Calculator/Operator.java
  type Operator (line 3) | public enum Operator {

FILE: Java/Ch 16. Moderate/Q16_26_Calculator/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method collapseTerm (line 6) | public static Term collapseTerm(Term primary, Term secondary) {
    method applyOp (line 15) | public static double applyOp(double left, Operator op, double right) {
    method compute (line 33) | public static double compute(String sequence) {
    method main (line 57) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_26_Calculator/QuestionB.java
  class QuestionB (line 4) | public class QuestionB {
    type Operator (line 5) | public enum Operator {
    method parseNextOperator (line 10) | public static Operator parseNextOperator(String sequence, int offset) {
    method parseNextNumber (line 24) | public static int parseNextNumber(String seq, int offset) {
    method applyOp (line 34) | public static double applyOp(double left, Operator op, double right) {
    method priorityOfOperator (line 50) | public static int priorityOfOperator(Operator op) {
    method collapseTop (line 65) | public static void collapseTop(Operator futureTop, Stack<Double> numbe...
    method compute (line 79) | public static double compute(String sequence) {
    method main (line 113) | public static void main(String[] args) {

FILE: Java/Ch 16. Moderate/Q16_26_Calculator/Term.java
  class Term (line 5) | public class Term {
    method Term (line 9) | public Term(double v, Operator op) {
    method getNumber (line 14) | public double getNumber() {
    method getOperator (line 18) | public Operator getOperator() {
    method setNumber (line 22) | public void setNumber(double v) {
    method parseTermSequence (line 26) | public static ArrayList<Term> parseTermSequence(String sequence) {
    method parseOperator (line 50) | public static Operator parseOperator(char op) {
    method parseNextNumber (line 60) | public static int parseNextNumber(String sequence, int offset) {

FILE: Java/Ch 17. Hard/Q17_01_Add_Without_Plus/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method add (line 5) | public static int add(int a, int b) {
    method main (line 12) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_01_Add_Without_Plus/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method add (line 5) | public static int add(int a, int b) {
    method main (line 15) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_01_Add_Without_Plus/Tester.java
  class Tester (line 3) | public class Tester {
    method randomInt (line 4) | public static int randomInt(int n) {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_02_Shuffle/Question.java
  class Question (line 7) | public class Question {
    method shuffleArrayRecursively (line 8) | public static int[] shuffleArrayRecursively(int[] cards, int i) {
    method shuffleArrayIteratively (line 27) | public static void shuffleArrayIteratively(int[] cards) {
    method main (line 37) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_03_Random_Set/Question.java
  class Question (line 7) | public class Question {
    method pickMRandomly (line 11) | public static int[] pickMRandomly(int[] original, int m) {
    method main (line 22) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_03_Random_Set/QuestionAlternate.java
  class QuestionAlternate (line 7) | public class QuestionAlternate {
    method pickMRecursively (line 10) | public static int[] pickMRecursively(int[] original, int m, int i) {
    method pickMIteratively (line 31) | public static int[] pickMIteratively(int[] original, int m) {
    method main (line 53) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_04_Missing_Number/BitInteger.java
  class BitInteger (line 3) | public class BitInteger {
    method BitInteger (line 6) | public BitInteger() {
    method BitInteger (line 11) | public BitInteger(int value){
    method fetch (line 20) | public int fetch(int k){
    method set (line 26) | public void set(int k, int bitValue){
    method set (line 32) | public void set(int k, char bitValue){
    method set (line 38) | public void set(int k, boolean bitValue){
    method swapValues (line 42) | public void swapValues(BitInteger number) {
    method toInt (line 50) | public int toInt() {

FILE: Java/Ch 17. Hard/Q17_04_Missing_Number/Question.java
  class Question (line 6) | public class Question {
    method initialize (line 8) | public static ArrayList<BitInteger> initialize(int n, int missing) {
    method findMissing (line 26) | public static int findMissing(ArrayList<BitInteger> array) {
    method findMissing (line 30) | private static int findMissing(ArrayList<BitInteger> input, int column) {
    method main (line 54) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_05_Letters_and_Numbers/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method extractSubarray (line 4) | public static char[] extractSubarray(char[] array, int start, int end) {
    method hasEqualLettersNumbers (line 13) | public static boolean hasEqualLettersNumbers(char[] array, int start, ...
    method findLongestSubarray (line 25) | public static char[] findLongestSubarray(char[] array) {
    method main (line 36) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_05_Letters_and_Numbers/QuestionB.java
  class QuestionB (line 6) | public class QuestionB {
    method computeDeltaArray (line 9) | public static int[] computeDeltaArray(char[] array) {
    method findLongestMatch (line 25) | public static int[] findLongestMatch(int[] deltas) {
    method extract (line 45) | public static char[] extract(char[] array, int start, int end) {
    method findLongestSubarray (line 54) | public static char[] findLongestSubarray(char[] array) {
    method isEqual (line 66) | public static boolean isEqual(char[] array, int start, int end) {
    method main (line 78) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_05_Letters_and_Numbers/Tester.java
  class Tester (line 3) | public class Tester {
    method main (line 8) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_06_Count_of_2s/Question.java
  class Question (line 3) | public class Question {
    method count2sInRangeAtDigit (line 4) | public static int count2sInRangeAtDigit(int number, int d) {
    method count2sInRange (line 22) | public static int count2sInRange(int number) {
    method count2sR (line 31) | public static int count2sR(int n) {
    method main (line 64) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_06_Count_of_2s/QuestionBrute.java
  class QuestionBrute (line 3) | public class QuestionBrute {
    method numberOf2s (line 5) | public static int numberOf2s(int n) {
    method numberOf2sInRange (line 16) | public static int numberOf2sInRange(int n) {
    method main (line 24) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_07_Baby_Names/Graph.java
  class Graph (line 6) | public class Graph {
    method Graph (line 10) | public Graph() {
    method hasNode (line 15) | public boolean hasNode(String name) {
    method createNode (line 19) | public GraphNode createNode(String name, int freq) {
    method getNode (line 30) | private GraphNode getNode(String name) {
    method getNodes (line 34) | public ArrayList<GraphNode> getNodes() {
    method addEdge (line 38) | public void addEdge(String startName, String endName) {

FILE: Java/Ch 17. Hard/Q17_07_Baby_Names/GraphNode.java
  class GraphNode (line 6) | public class GraphNode {
    method GraphNode (line 13) | public GraphNode(String nm, int freq) {
    method getName (line 20) | public String getName() {
    method getFrequency (line 24) | public int getFrequency() {
    method addNeighbor (line 28) | public boolean addNeighbor(GraphNode node) {
    method getNeighbors (line 37) | public ArrayList<GraphNode> getNeighbors() {
    method isVisited (line 41) | public boolean isVisited() {
    method setIsVisited (line 45) | public void setIsVisited(boolean v) {

FILE: Java/Ch 17. Hard/Q17_07_Baby_Names/NameSet.java
  class NameSet (line 6) | public class NameSet {
    method NameSet (line 11) | public NameSet(String name, int freq) {
    method getNames (line 17) | public Set<String> getNames() {
    method getRootName (line 21) | public String getRootName() {
    method copyNamesWithFrequency (line 25) | public void copyNamesWithFrequency(Set<String> more, int freq) {
    method getFrequency (line 30) | public int getFrequency() {
    method size (line 34) | public int size() {

FILE: Java/Ch 17. Hard/Q17_07_Baby_Names/QuestionA.java
  class QuestionA (line 8) | public class QuestionA {
    method constructGroups (line 12) | public static HashMap<String, NameSet> constructGroups(HashMap<String,...
    method mergeClasses (line 23) | public static void mergeClasses(HashMap<String, NameSet> groups, Strin...
    method convertToMap (line 47) | public static HashMap<String, Integer> convertToMap(HashMap<String, Na...
    method trulyMostPopular (line 55) | public static HashMap<String, Integer> trulyMostPopular(HashMap<String...
    method main (line 61) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_07_Baby_Names/QuestionB.java
  class QuestionB (line 6) | public class QuestionB {
    method constructGraph (line 8) | public static Graph constructGraph(HashMap<String, Integer> names) {
    method connectEdges (line 19) | public static void connectEdges(Graph graph, String[][] synonyms) {
    method getComponentFrequency (line 29) | public static int getComponentFrequency(GraphNode node) {
    method getTrueFrequencies (line 43) | public static HashMap<String, Integer> getTrueFrequencies(Graph graph) {
    method trulyMostPopular (line 55) | public static HashMap<String, Integer> trulyMostPopular(HashMap<String...
    method main (line 62) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_08_Circus_Tower/HtWt.java
  class HtWt (line 3) | public class HtWt implements Comparable<HtWt> {
    method HtWt (line 6) | public HtWt(int h, int w) { height = h; weight = w; }
    method compareTo (line 8) | public int compareTo(HtWt second) {
    method toString (line 16) | public String toString() {
    method isBefore (line 24) | public boolean isBefore(HtWt other) {

FILE: Java/Ch 17. Hard/Q17_08_Circus_Tower/QuestionA.java
  class QuestionA (line 6) | public class QuestionA {
    method longestIncreasingSeq (line 7) | public static ArrayList<HtWt> longestIncreasingSeq(ArrayList<HtWt> ite...
    method max (line 13) | private static ArrayList<HtWt> max(ArrayList<HtWt> seq1, ArrayList<HtW...
    method canAppend (line 22) | private static boolean canAppend(ArrayList<HtWt> solution, HtWt value) {
    method bestSeqAtIndex (line 33) | private static ArrayList<HtWt> bestSeqAtIndex(ArrayList<HtWt> array, A...
    method initialize (line 49) | public static ArrayList<HtWt> initialize() {
    method printList (line 82) | public static void printList(ArrayList<HtWt> list) {
    method main (line 89) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_08_Circus_Tower/QuestionB.java
  class QuestionB (line 6) | public class QuestionB {
    method max (line 9) | private static ArrayList<HtWt> max(ArrayList<HtWt> seq1, ArrayList<HtW...
    method canAppend (line 18) | private static boolean canAppend(ArrayList<HtWt> solution, HtWt value) {
    method longestIncreasingSeq (line 29) | public static ArrayList<HtWt> longestIncreasingSeq(ArrayList<HtWt> arr...
    method bestSeqAtIndex (line 43) | private static ArrayList<HtWt> bestSeqAtIndex(ArrayList<HtWt> array, A...
    method initialize (line 61) | public static ArrayList<HtWt> initialize() {
    method printList (line 94) | public static void printList(ArrayList<HtWt> list) {
    method main (line 100) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_08_Circus_Tower/QuestionOld.java
  class QuestionOld (line 6) | public class QuestionOld {
    method seqWithMaxLength (line 9) | private static ArrayList<HtWt> seqWithMaxLength(ArrayList<HtWt> seq1, ...
    method longestIncreasingSubsequence (line 18) | private static void longestIncreasingSubsequence(ArrayList<HtWt> array...
    method longestIncreasingSeq (line 44) | public static ArrayList<HtWt> longestIncreasingSeq(ArrayList<HtWt> arr...
    method initialize (line 58) | public static ArrayList<HtWt> initialize() {
    method printList (line 91) | public static void printList(ArrayList<HtWt> list) {
    method main (line 97) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_08_Circus_Tower/Tester.java
  class Tester (line 5) | public class Tester {
    method randomInt (line 6) | public static int randomInt(int n) {
    method validate (line 10) | public static boolean validate(ArrayList<HtWt> seq) {
    method main (line 21) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_09_Kth_Multiple/QuestionA.java
  class QuestionA (line 6) | public class QuestionA {
    method allPossibleKFactors (line 8) | public static ArrayList<Integer> allPossibleKFactors(int k) {
    method getKthMagicNumber (line 27) | public static int getKthMagicNumber(int k) {
    method main (line 33) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_09_Kth_Multiple/QuestionB.java
  class QuestionB (line 6) | public class QuestionB {
    method removeMin (line 8) | public static int removeMin(Queue<Integer> q) {
    method addProducts (line 21) | public static void addProducts(Queue<Integer> q, int v) {
    method getKthMagicNumber (line 27) | public static int getKthMagicNumber(int k) {
    method main (line 41) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_09_Kth_Multiple/QuestionC.java
  class QuestionC (line 6) | public class QuestionC {
    method printQueue (line 7) | public static void printQueue(Queue<Integer> q, int x) {
    method getKthMagicNumber (line 15) | public static int getKthMagicNumber(int k) {
    method main (line 44) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_10_Majority_Element/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method validate (line 4) | public static boolean validate(int[] array, int majority) {
    method findMajorityElement (line 15) | public static int findMajorityElement(int[] array) {
    method main (line 24) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_10_Majority_Element/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method getCandidate (line 5) | public static int getCandidate(int[] array) {
    method validate (line 21) | public static boolean validate(int[] array, int majority) {
    method findMajorityElement (line 32) | public static int findMajorityElement(int[] array) {
    method main (line 37) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_11_Word_Distance/LocationPair.java
  class LocationPair (line 3) | public class LocationPair {
    method LocationPair (line 6) | public LocationPair(int first, int second) {
    method setLocations (line 10) | public void setLocations(int first, int second) {
    method setLocations (line 15) | public void setLocations(LocationPair loc) {
    method distance (line 19) | public int distance() {
    method isValid (line 23) | public boolean isValid() {
    method updateWithMin (line 27) | public void updateWithMin(LocationPair loc) {
    method toString (line 33) | @Override

FILE: Java/Ch 17. Hard/Q17_11_Word_Distance/QuestionA.java
  class QuestionA (line 5) | public class QuestionA {
    method findClosest (line 7) | public static LocationPair findClosest(String[] words, String word1, S...
    method main (line 23) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_11_Word_Distance/QuestionB.java
  class QuestionB (line 9) | public class QuestionB {
    method getWordLocations (line 11) | public static HashMapList<String, Integer> getWordLocations(String[] w...
    method findMinDistancePair (line 19) | public static LocationPair findMinDistancePair(ArrayList<Integer> arra...
    method findClosest (line 42) | public static LocationPair findClosest(String word1, String word2, Has...
    method main (line 48) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_11_Word_Distance/Tester.java
  class Tester (line 9) | public class Tester {
    method wordAtLocation (line 11) | public static String wordAtLocation(String[] words, int loc) {
    method searchConfirm (line 19) | public static boolean searchConfirm(String[] words, String word1, Stri...
    method main (line 41) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_12_BiNode/BiNode.java
  class BiNode (line 3) | public class BiNode {
    method BiNode (line 7) | public BiNode(int d) {

FILE: Java/Ch 17. Hard/Q17_12_BiNode/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    class NodePair (line 4) | private static class NodePair {
      method NodePair (line 8) | public NodePair(BiNode head, BiNode tail)  {
    method convert (line 14) | public static NodePair convert(BiNode root) {
    method concat (line 33) | public static void concat(BiNode x, BiNode y) {
    method printLinkedListTree (line 38) | public static void printLinkedListTree(BiNode root) {
    method createTree (line 48) | public static BiNode createTree() {
    method printAsTree (line 62) | public static void printAsTree(BiNode root, String spaces) {
    method main (line 72) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_12_BiNode/QuestionB.java
  class QuestionB (line 3) | public class QuestionB {
    method convert (line 5) | public static BiNode convert(BiNode root) {
    method getTail (line 24) | public static BiNode getTail(BiNode node) {
    method concat (line 35) | public static void concat(BiNode x, BiNode y) {
    method printLinkedListTree (line 40) | public static void printLinkedListTree(BiNode root) {
    method createTree (line 50) | public static BiNode createTree() {
    method printAsTree (line 64) | public static void printAsTree(BiNode root, String spaces) {
    method main (line 74) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_12_BiNode/QuestionC.java
  class QuestionC (line 4) | public class QuestionC {
    method printAsTree (line 6) | public static void printAsTree(BiNode root, String spaces) {
    method createTree (line 16) | public static BiNode createTree() {
    method printLinkedListTree (line 30) | public static void printLinkedListTree(BiNode root) {
    method convertToCircular (line 40) | public static BiNode convertToCircular(BiNode root) {
    method convert (line 77) | public static BiNode convert(BiNode root) {
    method concat (line 84) | public static void concat(BiNode x, BiNode y) {
    method main (line 89) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_13_ReSpace/ParseResult.java
  class ParseResult (line 3) | public class ParseResult {
    method ParseResult (line 6) | public ParseResult(int inv, String p) {
    method clone (line 11) | public ParseResult clone() {
    method min (line 15) | public static ParseResult min(ParseResult r1, ParseResult r2) {

FILE: Java/Ch 17. Hard/Q17_13_ReSpace/QuestionA.java
  class QuestionA (line 6) | public class QuestionA {
    method bestSplit (line 7) | public static String bestSplit(HashSet<String> dictionary, String sent...
    method split (line 12) | public static ParseResult split(HashSet<String> dictionary, String sen...
    method clean (line 45) | public static String clean(String str) {
    method main (line 53) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_13_ReSpace/QuestionB.java
  class QuestionB (line 6) | public class QuestionB {
    method bestSplit (line 8) | public static String bestSplit(HashSet<String> dictionary, String sent...
    method split (line 14) | public static ParseResult split(HashSet<String> dictionary, String sen...
    method clean (line 49) | public static String clean(String str) {
    method main (line 57) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_14_Smallest_K/QuestionA.java
  class QuestionA (line 7) | public class QuestionA {
    method smallestK (line 9) | public static int[] smallestK(int[] array, int k) {
    method main (line 25) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_14_Smallest_K/QuestionB.java
  class QuestionB (line 8) | public class QuestionB {
    class MaxHeapComparator (line 10) | public static class MaxHeapComparator implements Comparator<Integer> {
      method compare (line 11) | public int compare(Integer x, Integer y) {
    method smallestK (line 16) | public static int[] smallestK(int[] array, int k) {
    method heapToIntArray (line 26) | public static int[] heapToIntArray(PriorityQueue<Integer> heap) {
    method getKMaxHeap (line 35) | public static PriorityQueue<Integer> getKMaxHeap(int[] array, int k) {
    method main (line 48) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_14_Smallest_K/QuestionC.java
  class QuestionC (line 7) | public class QuestionC {
    method smallestK (line 9) | public static int[] smallestK(int[] array, int k) {
    method rank (line 27) | public static int rank(int[] array, int rank) {
    method rank (line 32) | public static int rank(int[] array, int left, int right, int rank) {
    method partition (line 47) | public static int partition(int[] array, int left, int right, int pivo...
    method randomIntInRange (line 70) | public static int randomIntInRange(int min, int max) {
    method swap (line 76) | public static void swap(int[] array, int i, int j) {
    method max (line 83) | public static int max(int[] array, int left, int right) {
    method main (line 91) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_14_Smallest_K/QuestionD.java
  class QuestionD (line 7) | public class QuestionD {
    class PartitionResult (line 8) | public static class PartitionResult {
      method PartitionResult (line 11) | public PartitionResult(int left, int middle) {
    method smallestK (line 17) | public static int[] smallestK(int[] array, int k) {
    method rank (line 39) | public static int rank(int[] array, int k) {
    method rank (line 47) | private static int rank(int[] array, int k, int start, int end) {
    method partition (line 64) | private static PartitionResult partition(int[] array, int start, int e...
    method randomIntInRange (line 93) | public static int randomIntInRange(int min, int max) {
    method swap (line 99) | public static void swap(int[] array, int i, int j) {
    method main (line 105) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_14_Smallest_K/Tester.java
  class Tester (line 7) | public class Tester {
    method rankB (line 9) | public static int rankB(int[] array, int rank) {
    method swap (line 15) | public static void swap(int[] array, int i, int j) {
    method isUnique (line 21) | public static boolean isUnique(int[] array) {
    method max (line 32) | public static int max(int[] array, int left, int right) {
    method randomInt (line 40) | public static int randomInt(int n) {
    method randomIntInRange (line 44) | public static int randomIntInRange(int min, int max) {
    method isEqual (line 48) | public static boolean isEqual(int[] array1, int[] array2) {
    method isEquivalent (line 60) | public static boolean isEquivalent(int[] array1, int[] array2) {
    method testArray (line 66) | public static boolean testArray(int[] array1) {
    method main (line 84) | public static void main(String[] args) {

FILE: Java/Ch 17. Hard/Q17_15_Longest_Word/LengthComparator.java
  class LengthComparator (line 5) | public class LengthComparator implements Comparator<String> {
    method compare (line 6) | public int compare(String o1, String o2) {

FILE: Java/Ch 17. Hard/Q17_15_Longest_Word/Question.java
  class Question (line 6) | public class Question {
    method printLongestWord (line 7) | public static String printLongestWord(String arr[]) {
    method canBuildWord (line 22) | public static boolean canBuildWord(String str, boolean isOriginalWord,...
    method main (line 38) | public static void main(String[] args) {
    method createGiantArray (line 43) | public static String[] createGiantArray() {

FILE: Java/Ch 17. Hard/Q17_16_The_Masseuse/QuestionA.java
  class QuestionA (line 3) | public class QuestionA {
    method maxMinutes (line 4) | public static int maxMinutes(int[] massages) {
    method maxMinutes (line 8) | public static int maxMinutes(int[] massages, int i
Condensed preview — 592 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (941K chars).
[
  {
    "path": ".classpath",
    "chars": 1281,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<classpath>\n\t<classpathentry kind=\"src\" path=\"Java/Introduction\"/>\n\t<classpathent"
  },
  {
    "path": ".gitignore",
    "chars": 5,
    "preview": "bin/\n"
  },
  {
    "path": ".gitmodules",
    "chars": 1626,
    "preview": "[submodule \"php\"]\n\tpath = php\n\turl = https://github.com/careercup/CtCI-6th-Edition-php.git\n[submodule \"cpp\"]\n\tpath = cpp"
  },
  {
    "path": ".project",
    "chars": 365,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<projectDescription>\n\t<name>CtCIv6</name>\n\t<comment></comment>\n\t<projects>\n\t</pro"
  },
  {
    "path": "Java/Big O/Example_16/Example.java",
    "chars": 358,
    "preview": "package Example_16;\n\npublic class Example {\n\n\tpublic static int powersOf2(int n) {\n\t\tif (n < 1) {\n\t\t\treturn 0;\n\t\t} else "
  },
  {
    "path": "Java/Big O/QVI_11_Print_Sorted_Strings/Question.java",
    "chars": 926,
    "preview": "package QVI_11_Print_Sorted_Strings;\n\n\npublic class Question {\n\n\tpublic static int numChars = 26;\n\t\n\tpublic static void "
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_01_Is_Unique/QuestionA.java",
    "chars": 577,
    "preview": "package Q1_01_Is_Unique;\r\n\r\npublic class QuestionA {\r\n\tpublic static boolean isUniqueChars(String str) {\r\n\t\tif (str.leng"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_01_Is_Unique/QuestionB.java",
    "chars": 640,
    "preview": "package Q1_01_Is_Unique;\r\n\r\npublic class QuestionB {\r\n\r\n\t/* Assumes only letters a through z. */\r\n\tpublic static boolean"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_01_Is_Unique/Tester.java",
    "chars": 447,
    "preview": "package Q1_01_Is_Unique;\n\npublic class Tester {\n\t\n\tpublic static void main(String[] args) {\n\t\tString[] words = {\"abcde\","
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_02_Check_Permutation/QuestionA.java",
    "chars": 656,
    "preview": "package Q1_02_Check_Permutation;\r\n\r\npublic class QuestionA {\t\r\n\tpublic static String sort(String s) {\r\n\t\tchar[] content "
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_02_Check_Permutation/QuestionB.java",
    "chars": 940,
    "preview": "package Q1_02_Check_Permutation;\r\n\r\npublic class QuestionB {\t\r\n\tpublic static boolean permutation(String s, String t) {\r"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_03_URLify/Question.java",
    "chars": 1138,
    "preview": "package Q1_03_URLify;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class Question {\r\n\t// Assume string has sufficien"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/Common.java",
    "chars": 600,
    "preview": "package Q1_04_Palindrome_Permutation;\n\npublic class Common {\n\n\tpublic static int getCharNumber(Character c) {\n\t\tint a = "
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/QuestionA.java",
    "chars": 602,
    "preview": "package Q1_04_Palindrome_Permutation;\n\npublic class QuestionA {\t\n\tpublic static boolean checkMaxOneOdd(int[] table) {\n\t\t"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/QuestionB.java",
    "chars": 731,
    "preview": "package Q1_04_Palindrome_Permutation;\n\npublic class QuestionB {\t\n\n\tpublic static boolean isPermutationOfPalindrome(Strin"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/QuestionC.java",
    "chars": 1184,
    "preview": "package Q1_04_Palindrome_Permutation;\n\npublic class QuestionC {\n\t/* Toggle the ith bit in the integer. */\n\tpublic static"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_04_Palindrome_Permutation/Tester.java",
    "chars": 651,
    "preview": "package Q1_04_Palindrome_Permutation;\n\npublic class Tester {\n\n\t\n\tpublic static void main(String[] args) {\n\t\tString[] str"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionA.java",
    "chars": 1297,
    "preview": "package Q1_05_One_Away;\n\npublic class QuestionA {\n\n\tpublic static boolean oneEditReplace(String s1, String s2) {\n\t\tboole"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionB.java",
    "chars": 1266,
    "preview": "package Q1_05_One_Away;\n\npublic class QuestionB {\t\npublic static boolean oneEditAway(String first, String second) {\n\t\t/*"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_05_One_Away/Tester.java",
    "chars": 1155,
    "preview": "package Q1_05_One_Away;\n\npublic class Tester {\n\t\n\tpublic static void test(String a, String b, boolean expected) {\n\t\tbool"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_06_String_Compression/QuestionA.java",
    "chars": 728,
    "preview": "package Q1_06_String_Compression;\r\n\r\npublic class QuestionA {\t\r\n\tpublic static String compressBad(String str) {\r\n\t\tStrin"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_06_String_Compression/QuestionB.java",
    "chars": 756,
    "preview": "package Q1_06_String_Compression;\r\n\r\npublic class QuestionB {\t\r\n\tpublic static String compress(String str) {\r\n\t\tStringBu"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_06_String_Compression/QuestionC.java",
    "chars": 1323,
    "preview": "package Q1_06_String_Compression;\r\n\r\npublic class QuestionC {\t\r\n\tpublic static String compress(String str) {\r\n\t\tint fina"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_06_String_Compression/Tester.java",
    "chars": 314,
    "preview": "package Q1_06_String_Compression;\n\npublic class Tester {\n\n\tpublic static void main(String[] args) {\n\t\tString str = \"aaaa"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_07_Rotate_Matrix/Question.java",
    "chars": 1064,
    "preview": "package Q1_07_Rotate_Matrix;\r\n\r\nimport CtCILibrary.*;\r\n\r\npublic class Question {\r\n\r\n\tpublic static boolean rotate(int[]["
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_08_Zero_Matrix/QuestionA.java",
    "chars": 1948,
    "preview": "package Q1_08_Zero_Matrix;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class QuestionA {\r\n\tpublic static void nulli"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_08_Zero_Matrix/QuestionB.java",
    "chars": 2502,
    "preview": "package Q1_08_Zero_Matrix;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class QuestionB {\r\n\tpublic static void nulli"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_08_Zero_Matrix/Tester.java",
    "chars": 1291,
    "preview": "package Q1_08_Zero_Matrix;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class Tester {\r\n\tpublic static boolean matri"
  },
  {
    "path": "Java/Ch 01. Arrays and Strings/Q1_09_String_Rotation/Question.java",
    "chars": 930,
    "preview": "package Q1_09_String_Rotation;\r\n\r\npublic class Question {\r\n\tpublic static boolean isSubstring(String big, String small) "
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_01_Remove_Dups/QuestionA.java",
    "chars": 933,
    "preview": "package Q2_01_Remove_Dups;\r\n\r\nimport java.util.HashSet;\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic class QuestionA {\r"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_01_Remove_Dups/QuestionB.java",
    "chars": 981,
    "preview": "package Q2_01_Remove_Dups;\r\n\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic class QuestionB {\r\n\tpublic static void delete"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_01_Remove_Dups/QuestionC.java",
    "chars": 1618,
    "preview": "package Q2_01_Remove_Dups;\r\n\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic class QuestionC {\r\n\tpublic static void delete"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_01_Remove_Dups/Tester.java",
    "chars": 867,
    "preview": "package Q2_01_Remove_Dups;\n\nimport CtCILibrary.LinkedListNode;\n\npublic class Tester {\n\n\tpublic static void main(String[]"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/QuestionA.java",
    "chars": 609,
    "preview": "package Q2_02_Return_Kth_To_Last;\r\n\r\nimport CtCILibrary.*;\r\n\r\npublic class QuestionA {\r\n\r\n\tpublic static int printKthToL"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/QuestionB.cpp",
    "chars": 968,
    "preview": "#include <iostream>\nusing namespace std;\n\nstruct node {\n\tnode * next;\n\tint data;\n};\n\nnode* nthToLast(node* head, int k, "
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/QuestionC.java",
    "chars": 951,
    "preview": "package Q2_02_Return_Kth_To_Last;\r\n\r\nimport CtCILibrary.*;\r\n\r\npublic class QuestionC {\r\n\tpublic static class Index {\r\n\t\t"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/QuestionD.java",
    "chars": 929,
    "preview": "package Q2_02_Return_Kth_To_Last;\r\n\r\nimport CtCILibrary.*;\r\n\r\npublic class QuestionD {\r\n\t\r\n\tpublic static LinkedListNode"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_02_Return_Kth_To_Last/Tester.java",
    "chars": 146,
    "preview": "package Q2_02_Return_Kth_To_Last;\n\nimport CtCILibrary.AssortedMethods;\n\npublic class Tester {\n\n\t\n\tpublic static void mai"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_03_Delete_Middle_Node/Question.java",
    "chars": 640,
    "preview": "package Q2_03_Delete_Middle_Node;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic c"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_04_Partition/Question.java",
    "chars": 1492,
    "preview": "package Q2_04_Partition;\r\n\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic class Question {\r\n\r\n\tpublic static LinkedListNo"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_04_Partition/QuestionB.java",
    "chars": 1492,
    "preview": "package Q2_04_Partition;\r\n\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic class QuestionB {\r\n\r\n\tpublic static LinkedListN"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_04_Partition/QuestionC.java",
    "chars": 1132,
    "preview": "package Q2_04_Partition;\n\nimport CtCILibrary.LinkedListNode;\n\npublic class QuestionC {\n\n\tpublic static LinkedListNode pa"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_04_Partition/Tester.java",
    "chars": 893,
    "preview": "package Q2_04_Partition;\n\nimport CtCILibrary.LinkedListNode;\n\npublic class Tester {\n\t\n\tpublic static LinkedListNode crea"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_05_Sum_Lists/PartialSum.java",
    "chars": 156,
    "preview": "package Q2_05_Sum_Lists;\r\n\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic class PartialSum {\r\n\tpublic LinkedListNode sum "
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_05_Sum_Lists/QuestionA.java",
    "chars": 1861,
    "preview": "package Q2_05_Sum_Lists;\r\n\r\n\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic class QuestionA {\r\n\tprivate static LinkedList"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_05_Sum_Lists/QuestionB.java",
    "chars": 2462,
    "preview": "package Q2_05_Sum_Lists;\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic class QuestionB {\r\n\tprivate static int length(Lin"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_06_Palindrome/QuestionA.java",
    "chars": 1411,
    "preview": "package Q2_06_Palindrome;\r\n\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic class QuestionA {\r\n\tpublic static boolean isPa"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_06_Palindrome/QuestionB.java",
    "chars": 1337,
    "preview": "package Q2_06_Palindrome;\r\n\r\nimport CtCILibrary.LinkedListNode;\r\n\r\nimport java.util.Stack;\r\n\r\npublic class QuestionB {\r\n"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_06_Palindrome/QuestionC.java",
    "chars": 1938,
    "preview": "package Q2_06_Palindrome;\r\n\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic class QuestionC {\r\n\tpublic static class Result"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_06_Palindrome/Tester.java",
    "chars": 1259,
    "preview": "package Q2_06_Palindrome;\r\n\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic class Tester {\r\n\t\r\n\tpublic static void main(St"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_07_Intersection/Question.java",
    "chars": 2282,
    "preview": "package Q2_07_Intersection;\n\nimport CtCILibrary.AssortedMethods;\nimport CtCILibrary.LinkedListNode;\n\npublic class Questi"
  },
  {
    "path": "Java/Ch 02. Linked Lists/Q2_08_Loop_Detection/Question.java",
    "chars": 1428,
    "preview": "package Q2_08_Loop_Detection;\r\n\r\nimport CtCILibrary.LinkedListNode;\r\n\r\npublic class Question {\r\n\r\n\tpublic static LinkedL"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Introduction/MyQueue.java",
    "chars": 816,
    "preview": "package Introduction;\n\nimport java.util.NoSuchElementException;\n\npublic class MyQueue<T> {\n\tprivate static class QueueNo"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Introduction/MyStack.java",
    "chars": 695,
    "preview": "package Introduction;\n\nimport java.util.EmptyStackException;\n\npublic class MyStack<T> {\n\tprivate static class StackNode<"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Introduction/QueueTester.java",
    "chars": 1369,
    "preview": "package Introduction;\n\nimport java.util.LinkedList;\nimport java.util.NoSuchElementException;\nimport java.util.Queue;\n\nim"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Introduction/StackTester.java",
    "chars": 1306,
    "preview": "package Introduction;\n\nimport java.util.EmptyStackException;\nimport java.util.Stack;\n\nimport CtCILibrary.AssortedMethods"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/FixedMultiStack.java",
    "chars": 2144,
    "preview": "package Q3_01_Three_in_One;\r\n\r\nimport java.util.EmptyStackException;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic cl"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/FullStackException.java",
    "chars": 265,
    "preview": "package Q3_01_Three_in_One;\n\npublic class FullStackException extends Exception {\n\tprivate static final long serialVersio"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/MultiStack.java",
    "chars": 5634,
    "preview": "package Q3_01_Three_in_One;\n\nimport java.util.EmptyStackException;\n\nimport CtCILibrary.AssortedMethods;\n\npublic class Mu"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/QuestionA.java",
    "chars": 960,
    "preview": "package Q3_01_Three_in_One;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class QuestionA {\r\n\tpublic static void prin"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_01_Three_in_One/QuestionB.java",
    "chars": 1382,
    "preview": "package Q3_01_Three_in_One;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class QuestionB {\r\n\tpublic static void prin"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_02_Stack_Min/NodeWithMin.java",
    "chars": 189,
    "preview": "package Q3_02_Stack_Min;\r\n\r\nclass NodeWithMin {\r\n    public int value;\r\n    public int min;\r\n    public NodeWithMin(int "
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_02_Stack_Min/Question.java",
    "chars": 574,
    "preview": "package Q3_02_Stack_Min;\r\n\r\npublic class Question {\r\n\tpublic static void main(String[] args) {\r\n\t\tStackWithMin stack = n"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_02_Stack_Min/StackWithMin.java",
    "chars": 402,
    "preview": "package Q3_02_Stack_Min;\r\n\r\nimport java.util.Stack;\r\n\r\npublic class StackWithMin extends Stack<NodeWithMin> {\r\n    publi"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_02_Stack_Min/StackWithMin2.java",
    "chars": 556,
    "preview": "package Q3_02_Stack_Min;\r\n\r\nimport java.util.Stack;\r\n\r\npublic class StackWithMin2 extends Stack<Integer> {\r\n\tStack<Integ"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_03_Stack_of_Plates/Node.java",
    "chars": 174,
    "preview": "package Q3_03_Stack_of_Plates;\r\n\r\npublic class Node {\r\n\tpublic Node above;\r\n\tpublic Node below;\r\n\tpublic int value;\r\n\tpu"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_03_Stack_of_Plates/Question.java",
    "chars": 348,
    "preview": "package Q3_03_Stack_of_Plates;\r\n\r\npublic class Question {\r\n\tpublic static void main(String[] args) {\r\n\t\tint capacity_per"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_03_Stack_of_Plates/SetOfStacks.java",
    "chars": 1477,
    "preview": "package Q3_03_Stack_of_Plates;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.EmptyStackException;\r\n\r\npublic class Set"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_03_Stack_of_Plates/Stack.java",
    "chars": 1014,
    "preview": "package Q3_03_Stack_of_Plates;\r\n\r\nimport java.util.EmptyStackException;\r\n\r\npublic class Stack {\r\n\tprivate int capacity;\r"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_04_Queue_via_Stacks/MyQueue.java",
    "chars": 886,
    "preview": "package Q3_04_Queue_via_Stacks;\r\n\r\nimport java.util.Stack;\r\n\r\npublic class MyQueue<T> {\r\n\tStack<T> stackNewest, stackOld"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_04_Queue_via_Stacks/Question.java",
    "chars": 1318,
    "preview": "package Q3_04_Queue_via_Stacks;\r\n\r\nimport java.util.LinkedList;\r\nimport java.util.Queue;\r\n\r\nimport CtCILibrary.AssortedM"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_05_Sort_Stack/Question.java",
    "chars": 1739,
    "preview": "package Q3_05_Sort_Stack;\r\n\r\nimport java.util.Stack;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class Question {\r\n"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/Animal.java",
    "chars": 388,
    "preview": "package Q3_06_Animal_Shelter;\r\n\r\npublic abstract class Animal {\r\n\tprivate int order; \r\n\tprotected String name;\r\n\tpublic "
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/AnimalQueue.java",
    "chars": 1289,
    "preview": "package Q3_06_Animal_Shelter;\r\n\r\nimport java.util.LinkedList;\r\n\r\npublic class AnimalQueue {\r\n\tLinkedList<Dog> dogs = new"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/Cat.java",
    "chars": 173,
    "preview": "package Q3_06_Animal_Shelter;\r\n\r\npublic class Cat extends Animal {\r\n\tpublic Cat(String n) {\r\n\t\tsuper(n);\r\n\t}\r\n\t\r\n\tpublic"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/Dog.java",
    "chars": 171,
    "preview": "package Q3_06_Animal_Shelter;\r\n\r\npublic class Dog extends Animal {\r\n\tpublic Dog(String n) {\r\n\t\tsuper(n);\r\n\t}\r\n\t\r\n\tpublic"
  },
  {
    "path": "Java/Ch 03. Stacks and Queues/Q3_06_Animal_Shelter/Question.java",
    "chars": 795,
    "preview": "package Q3_06_Animal_Shelter;\r\n\r\npublic class Question {\r\n\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tAnimalQueue a"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Introduction/Traversals.java",
    "chars": 946,
    "preview": "package Introduction;\n\nimport CtCILibrary.TreeNode;\n\npublic class Traversals {\n\tpublic static void visit(TreeNode node) "
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_01_Route_Between_Nodes/Graph.java",
    "chars": 469,
    "preview": "package Q4_01_Route_Between_Nodes;\r\n\r\npublic class Graph {\r\n\tpublic static int MAX_VERTICES = 6;\r\n\tprivate Node vertices"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_01_Route_Between_Nodes/Node.java",
    "chars": 770,
    "preview": "package Q4_01_Route_Between_Nodes;\r\n\r\nclass Node {\r\n    private Node adjacent[];\r\n    public int adjacentCount;\r\n    pri"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_01_Route_Between_Nodes/Question.java",
    "chars": 1734,
    "preview": "package Q4_01_Route_Between_Nodes;\r\n\r\nimport java.util.LinkedList;\r\n\r\npublic class Question {\r\n\tpublic enum State {\r\n\t\tU"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_02_Minimal_Tree/Question.java",
    "chars": 479,
    "preview": "package Q4_02_Minimal_Tree;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class Question {\t\r\n\tpublic static void main(String"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_03_List_of_Depths/QuestionBFS.java",
    "chars": 1593,
    "preview": "package Q4_03_List_of_Depths;\r\n\r\nimport CtCILibrary.*;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.Iterator;\r\nimpor"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_03_List_of_Depths/QuestionDFS.java",
    "chars": 1760,
    "preview": "package Q4_03_List_of_Depths;\r\n\r\nimport CtCILibrary.*;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.Iterator;\r\nimpor"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_04_Check_Balanced/QuestionBrute.java",
    "chars": 1226,
    "preview": "package Q4_04_Check_Balanced;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class Quest"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_04_Check_Balanced/QuestionImproved.java",
    "chars": 1161,
    "preview": "package Q4_04_Check_Balanced;\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class QuestionImproved {\r\n\t\t\r\n\tpublic static int c"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_05_Validate_BST/IntWrapper.java",
    "chars": 126,
    "preview": "package Q4_05_Validate_BST;\r\n\r\npublic class IntWrapper {\r\n\tpublic IntWrapper(int m) {\r\n\t\tdata = m;\r\n\t}\r\n\tpublic int data"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_05_Validate_BST/Question.java",
    "chars": 2096,
    "preview": "package Q4_05_Validate_BST;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class Question {\r\n\tpublic static Integer lastPrint"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_05_Validate_BST/QuestionB.java",
    "chars": 3158,
    "preview": "package Q4_05_Validate_BST;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class Questio"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_06_Successor/Question.java",
    "chars": 1140,
    "preview": "package Q4_06_Successor;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class Question {\r\n\r\n\tpublic static TreeNode inorderSu"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/DFS/Graph.java",
    "chars": 677,
    "preview": "package Q4_07_Build_Order.DFS;\n\nimport java.util.ArrayList;\nimport java.util.HashMap;\n\npublic class Graph {\n\tprivate Arr"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/DFS/Project.java",
    "chars": 763,
    "preview": "package Q4_07_Build_Order.DFS;\n\nimport java.util.ArrayList;\nimport java.util.HashMap;\n\npublic class Project {\n\tpublic en"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/DFS/Question.java",
    "chars": 2733,
    "preview": "package Q4_07_Build_Order.DFS;\n\nimport java.util.ArrayList;\nimport java.util.Stack;\n\npublic class Question {\n\n\t/* Build "
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/EdgeRemoval/Graph.java",
    "chars": 685,
    "preview": "package Q4_07_Build_Order.EdgeRemoval;\n\nimport java.util.ArrayList;\nimport java.util.HashMap;\n\npublic class Graph {\n\tpri"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/EdgeRemoval/Project.java",
    "chars": 840,
    "preview": "package Q4_07_Build_Order.EdgeRemoval;\n\nimport java.util.ArrayList;\nimport java.util.HashMap;\n\npublic class Project {\n\tp"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_07_Build_Order/EdgeRemoval/Question.java",
    "chars": 3171,
    "preview": "package Q4_07_Build_Order.EdgeRemoval;\n\nimport java.util.ArrayList;\n\npublic class Question {\n\n\t/* Build the graph, addin"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/Question.java",
    "chars": 1844,
    "preview": "package Q4_08_First_Common_Ancestor;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class Question {\r\n\tstatic int TWO_NODES_F"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionA.java",
    "chars": 852,
    "preview": "package Q4_08_First_Common_Ancestor;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class QuestionA {\r\n\tpublic static TreeNod"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionB.java",
    "chars": 1243,
    "preview": "package Q4_08_First_Common_Ancestor;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class QuestionB {\r\n\tpublic static TreeNod"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionC.java",
    "chars": 1262,
    "preview": "package Q4_08_First_Common_Ancestor;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class QuestionC {\r\n\t\r\n\tpublic static Tree"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionD.java",
    "chars": 1287,
    "preview": "package Q4_08_First_Common_Ancestor;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class QuestionD {\r\n\t\r\n\tpublic static Tree"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionE.java",
    "chars": 1857,
    "preview": "package Q4_08_First_Common_Ancestor;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class QuestionE {\r\n\tpublic static class R"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionEBad.java",
    "chars": 1145,
    "preview": "package Q4_08_First_Common_Ancestor;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class QuestionEBad {\r\n\tpublic static Tree"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/QuestionF.java",
    "chars": 807,
    "preview": "package Q4_08_First_Common_Ancestor;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class QuestionF {\r\n\t\r\n\tpublic static Tree"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_08_First_Common_Ancestor/Tester.java",
    "chars": 1560,
    "preview": "package Q4_08_First_Common_Ancestor;\n\nimport java.util.ArrayList;\n\nimport CtCILibrary.TreeNode;\n\npublic class Tester {\n\t"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_09_BST_Sequences/Question.java",
    "chars": 2416,
    "preview": "package Q4_09_BST_Sequences;\n\nimport java.util.ArrayList;\nimport java.util.LinkedList;\n\nimport CtCILibrary.TreeNode;\n\npu"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_10_Check_Subtree/QuestionA.java",
    "chars": 1506,
    "preview": "package Q4_10_Check_Subtree;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class Questi"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_10_Check_Subtree/QuestionB.java",
    "chars": 2062,
    "preview": "package Q4_10_Check_Subtree;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class Questi"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_11_Random_Node/Question.java",
    "chars": 456,
    "preview": "package Q4_11_Random_Node;\n\npublic class Question {\n\n\tpublic static void main(String[] args) {\n\t\tint[] counts = new int["
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_11_Random_Node/Tree.java",
    "chars": 480,
    "preview": "package Q4_11_Random_Node;\n\nimport java.util.Random;\n\npublic class Tree {\n\tTreeNode root = null;\n\t\n\tpublic void insertIn"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_11_Random_Node/TreeNode.java",
    "chars": 1512,
    "preview": "package Q4_11_Random_Node;\r\n\r\nimport java.util.Random;\r\n\r\n/* One node of a binary tree. The data element stored is a sin"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_12_Paths_with_Sum/QuestionA.java",
    "chars": 2355,
    "preview": "package Q4_12_Paths_with_Sum;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class QuestionA {\r\n\t\r\n\tpublic static int countPa"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_12_Paths_with_Sum/QuestionB.java",
    "chars": 2786,
    "preview": "package Q4_12_Paths_with_Sum;\r\nimport java.util.HashMap;\r\n\r\nimport CtCILibrary.TreeNode;\r\n\r\npublic class QuestionB {\r\n\t\r"
  },
  {
    "path": "Java/Ch 04. Trees and Graphs/Q4_12_Paths_with_Sum/Tester.java",
    "chars": 805,
    "preview": "package Q4_12_Paths_with_Sum;\n\nimport CtCILibrary.AssortedMethods;\nimport CtCILibrary.TreeNode;\n\npublic class Tester {\n\n"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_01_Insertion/Question.java",
    "chars": 1284,
    "preview": "package Q5_01_Insertion;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class Question {\r\n\r\n\tpublic static int updateB"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_02_Binary_to_String/Question.java",
    "chars": 1440,
    "preview": "package Q5_02_Binary_to_String;\r\n\r\npublic class Question {\r\n\tpublic static String printBinary(double num) {\r\n\t\tif (num >"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/QuestionA.java",
    "chars": 935,
    "preview": "package Q5_03_Flip_Bit_to_Win;\n\npublic class QuestionA {\n\t\n\tpublic static int SEQUENCE_LENGTH = 32;\n\t\n\tpublic static boo"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/QuestionB.java",
    "chars": 1821,
    "preview": "package Q5_03_Flip_Bit_to_Win;\n\nimport java.util.ArrayList;\n\npublic class QuestionB {\n\t\n\tpublic static int longestSequen"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/QuestionC.java",
    "chars": 1752,
    "preview": "package Q5_03_Flip_Bit_to_Win;\n\npublic class QuestionC {\n\n\tpublic static int SEQUENCE_LENGTH = 32;\n\t\n\t/* Given set of th"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/QuestionD.java",
    "chars": 990,
    "preview": "package Q5_03_Flip_Bit_to_Win;\n\npublic class QuestionD {\n\n\tpublic static int flipBit(int a) {\n\t\t/* If all 1s, this is al"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_03_Flip_Bit_to_Win/Tester.java",
    "chars": 1131,
    "preview": "package Q5_03_Flip_Bit_to_Win;\n\npublic class Tester {\n\t\n\tpublic static boolean checkRange(int start, int range) {\n\t\tfor "
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_04_Next_Number/QuestionA.java",
    "chars": 1318,
    "preview": "package Q5_04_Next_Number;\r\n\r\npublic class QuestionA {\r\n\r\n\tpublic static int countOnes(int i) {\r\n\t\tint count = 0;\r\n\t\twhi"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_04_Next_Number/QuestionB.java",
    "chars": 3255,
    "preview": "package Q5_04_Next_Number;\r\n\r\npublic class QuestionB {\r\n\t\r\n\tpublic static int getNext(int n) {\r\n\t\tint c = n;\r\n\t\tint c0 ="
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_04_Next_Number/QuestionC.java",
    "chars": 1549,
    "preview": "package Q5_04_Next_Number;\r\n\r\npublic class QuestionC {\r\n\tpublic static int getNextArith(int n) {\r\n\t\tint c = n;\r\n\t\tint c0"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_04_Next_Number/Tester.java",
    "chars": 762,
    "preview": "package Q5_04_Next_Number;\r\n\r\npublic class Tester {\r\n\tpublic static void binPrint(int i) {\r\n\t\tSystem.out.println(i + \": "
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_06_Conversion/QuestionA.java",
    "chars": 633,
    "preview": "package Q5_06_Conversion;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class QuestionA {\r\n\tpublic static int bitSwap"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_06_Conversion/QuestionB.java",
    "chars": 882,
    "preview": "package Q5_06_Conversion;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class QuestionB {\r\n\tpublic static int bitSwap"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_06_Conversion/Tester.java",
    "chars": 823,
    "preview": "package Q5_06_Conversion;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class Tester {\r\n\tpublic static int bitSwapReq"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_07_Pairwise_Swap/Question.java",
    "chars": 466,
    "preview": "package Q5_07_Pairwise_Swap;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class Question {\r\n\r\n\tpublic static int swa"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Q5_08_Draw_Line/Question.java",
    "chars": 2132,
    "preview": "package Q5_08_Draw_Line;\r\n\r\npublic class Question {\r\n\tpublic static int computeByteNum(int width, int x, int y) {\r\n\t\tret"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Sample_Code/RightShifts.java",
    "chars": 882,
    "preview": "package Sample_Code;\n\nimport CtCILibrary.AssortedMethods;\n\npublic class RightShifts {\n\tpublic static int repeatedArithme"
  },
  {
    "path": "Java/Ch 05. Bit Manipulation/Sample_Code/Sample_Code.java",
    "chars": 2313,
    "preview": "package Sample_Code;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class Sample_Code {\r\n\r\n\tpublic static boolean getB"
  },
  {
    "path": "Java/Ch 06. Math and Logic Puzzles/Introduction/PrimeNumbers.java",
    "chars": 568,
    "preview": "package Introduction;\r\n\r\npublic class PrimeNumbers {\r\n\r\n\tpublic static boolean primeNaive(int n) {\r\n\t\tfor (int i = 2; i "
  },
  {
    "path": "Java/Ch 06. Math and Logic Puzzles/Introduction/SieveOfEratosthenes.java",
    "chars": 1700,
    "preview": "package Introduction;\r\n\r\npublic class SieveOfEratosthenes {\r\n\t\r\n\tpublic static void crossOff(boolean[] flags, int prime)"
  },
  {
    "path": "Java/Ch 06. Math and Logic Puzzles/Q6_05_Egg_Drop/Question.java",
    "chars": 1213,
    "preview": "package Q6_05_Egg_Drop;\n\npublic class Question {\n\tpublic static int breakingPoint = 89;\n\tpublic static int countDrops = "
  },
  {
    "path": "Java/Ch 06. Math and Logic Puzzles/Q6_07_The_Apocalypse/Question.java",
    "chars": 747,
    "preview": "package Q6_07_The_Apocalypse;\n\nimport java.util.Random;\n\npublic class Question {\n\tpublic static int[] runOneFamily() {\n\t"
  },
  {
    "path": "Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/Bottle.java",
    "chars": 300,
    "preview": "package Q6_10_Test_Strips;\n\npublic class Bottle {\n\tprivate boolean poisoned = false;\n\tprivate int id;\n\t\n\tpublic Bottle(i"
  },
  {
    "path": "Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/QuestionA.java",
    "chars": 2245,
    "preview": "package Q6_10_Test_Strips;\n\nimport java.util.ArrayList;\nimport java.util.Random;\n\npublic class QuestionA {\n\tpublic stati"
  },
  {
    "path": "Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/QuestionB.java",
    "chars": 3919,
    "preview": "package Q6_10_Test_Strips;\n\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.util.Random;\n\npublic class"
  },
  {
    "path": "Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/QuestionC.java",
    "chars": 2477,
    "preview": "package Q6_10_Test_Strips;\n\nimport java.util.ArrayList;\nimport java.util.Random;\n\npublic class QuestionC {\n\tpublic stati"
  },
  {
    "path": "Java/Ch 06. Math and Logic Puzzles/Q6_10_Test_Strips/TestStrip.java",
    "chars": 1562,
    "preview": "package Q6_10_Test_Strips;\n\nimport java.util.ArrayList;\n\npublic class TestStrip {\n\tpublic static int DAYS_FOR_RESULT = 7"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/BlackJackCard.java",
    "chars": 688,
    "preview": "package Q7_01_Deck_of_Cards;\r\n\r\npublic class BlackJackCard extends Card {\r\n\tpublic BlackJackCard(int c, Suit s) {\r\n\t\tsup"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/BlackJackGameAutomator.java",
    "chars": 2503,
    "preview": "package Q7_01_Deck_of_Cards;\r\n\r\nimport java.util.ArrayList;\r\n\r\npublic class BlackJackGameAutomator {\r\n\tprivate Deck<Blac"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/BlackJackHand.java",
    "chars": 1579,
    "preview": "package Q7_01_Deck_of_Cards;\r\n\r\nimport java.util.ArrayList;\r\n\r\npublic class BlackJackHand extends Hand<BlackJackCard> {\r"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/Card.java",
    "chars": 1135,
    "preview": "package Q7_01_Deck_of_Cards;\r\n\r\npublic abstract class Card {\r\n\tprivate boolean available = true;\r\n\t\r\n\t/* number or face "
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/Deck.java",
    "chars": 1260,
    "preview": "package Q7_01_Deck_of_Cards;\r\n\r\nimport java.util.ArrayList;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class Deck "
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/Hand.java",
    "chars": 424,
    "preview": "package Q7_01_Deck_of_Cards;\r\n\r\nimport java.util.ArrayList;\r\n\r\npublic class Hand <T extends Card> {\r\n\tprotected ArrayLis"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/Question.java",
    "chars": 1288,
    "preview": "package Q7_01_Deck_of_Cards;\r\n\r\nimport java.util.ArrayList;\r\n\r\npublic class Question {\r\n\r\n\t\r\n\tpublic static void main(St"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_01_Deck_of_Cards/Suit.java",
    "chars": 476,
    "preview": "package Q7_01_Deck_of_Cards;\r\n\r\npublic enum Suit { \r\n\tClub (0),\r\n\tDiamond (1),\r\n\tHeart (2),\r\n\tSpade (3);\r\n\t\r\n\tprivate in"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Call.java",
    "chars": 1071,
    "preview": "package Q7_02_Call_Center;\r\n\r\n/* Represents a call from a user. Calls have a minimum rank and are assigned to the\r\n * fi"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/CallHandler.java",
    "chars": 3684,
    "preview": "package Q7_02_Call_Center;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\n/* CallHandler represents the body "
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Caller.java",
    "chars": 172,
    "preview": "package Q7_02_Call_Center;\r\n\r\npublic class Caller {\r\n\tprivate String name;\r\n\tprivate int userId;\r\n\tpublic Caller(int id,"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Director.java",
    "chars": 177,
    "preview": "package Q7_02_Call_Center;\r\n\r\nclass Director extends Employee {\r\n    public Director(CallHandler callHandler) {\r\n    \tsu"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Employee.java",
    "chars": 1589,
    "preview": "package Q7_02_Call_Center;\r\n\r\n/* Employee is a super class for the Director, Manager, and Respondent classes. It is impl"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Manager.java",
    "chars": 174,
    "preview": "package Q7_02_Call_Center;\r\n\r\nclass Manager extends Employee {\r\n    public Manager(CallHandler callHandler) {\r\n    \tsupe"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Rank.java",
    "chars": 220,
    "preview": "package Q7_02_Call_Center;\r\n\r\npublic enum Rank {\r\n\tResponder (0),\r\n\tManager (1),\r\n\tDirector (2);\r\n\t\r\n\tprivate int value;"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Respondent.java",
    "chars": 182,
    "preview": "package Q7_02_Call_Center;\r\n\r\nclass Respondent extends Employee {\r\n    public Respondent(CallHandler callHandler) {\r\n   "
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_02_Call_Center/Test.java",
    "chars": 173,
    "preview": "package Q7_02_Call_Center;\r\n\r\npublic class Test {\r\n\r\n\t/**\r\n\t * @param args\r\n\t */\r\n\tpublic static void main(String[] args"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/CD.java",
    "chars": 50,
    "preview": "package Q7_03_Jukebox;\r\n\r\npublic class CD {\r\n\r\n}\r\n"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/CDPlayer.java",
    "chars": 470,
    "preview": "package Q7_03_Jukebox;\r\n\r\npublic class CDPlayer {\r\n\tprivate Playlist p;\r\n\tprivate CD c;\r\n\t\r\n\tpublic Playlist getPlaylist"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/JukeBox.java",
    "chars": 521,
    "preview": "package Q7_03_Jukebox;\r\n\r\nimport java.util.Set;\r\n\r\npublic class JukeBox {\r\n\tprivate CDPlayer cdPlayer;\r\n\tprivate User us"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/Playlist.java",
    "chars": 355,
    "preview": "package Q7_03_Jukebox;\r\n\r\nimport java.util.Queue;\r\n\r\npublic class Playlist {\r\n\tprivate Song song;\r\n\tprivate Queue<Song> "
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/Song.java",
    "chars": 125,
    "preview": "package Q7_03_Jukebox;\r\n\r\npublic class Song {\r\n\tprivate String songName;\r\n\tpublic String toString() { return songName; }"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/SongSelector.java",
    "chars": 245,
    "preview": "package Q7_03_Jukebox;\r\n\r\n\r\npublic class SongSelector {\r\n\tprivate Song currentSong;\r\n\tpublic SongSelector(Song s) { curr"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_03_Jukebox/User.java",
    "chars": 473,
    "preview": "package Q7_03_Jukebox;\r\n\r\npublic class User {\r\n\tprivate String name;\r\n\tpublic String getName() { return name; }\r\n\tpublic"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/Bus.java",
    "chars": 300,
    "preview": "package Q7_04_Parking_Lot;\r\n\r\npublic class Bus extends Vehicle {\r\n\tpublic Bus() {\r\n\t\tspotsNeeded = 5;\r\n\t\tsize = VehicleS"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/Car.java",
    "chars": 344,
    "preview": "package Q7_04_Parking_Lot;\r\n\r\npublic class Car extends Vehicle {\r\n\tpublic Car() {\r\n\t\tspotsNeeded = 1;\r\n\t\tsize = VehicleS"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/Level.java",
    "chars": 2651,
    "preview": "package Q7_04_Parking_Lot;\r\n\r\n/* Represents a level in a parking garage */\r\npublic class Level {\r\n\tprivate int floor;\r\n\t"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/Motorcycle.java",
    "chars": 289,
    "preview": "package Q7_04_Parking_Lot;\r\n\r\npublic class Motorcycle extends Vehicle {\r\n\tpublic Motorcycle() {\r\n\t\tspotsNeeded = 1;\r\n\t\ts"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/ParkingLot.java",
    "chars": 738,
    "preview": "package Q7_04_Parking_Lot;\r\n\r\npublic class ParkingLot {\r\n\tprivate Level[] levels;\r\n\tprivate final int NUM_LEVELS = 5;\r\n\t"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/ParkingSpot.java",
    "chars": 1500,
    "preview": "package Q7_04_Parking_Lot;\r\n\r\npublic class ParkingSpot {\r\n\tprivate Vehicle vehicle;\r\n\tprivate VehicleSize spotSize;\r\n\tpr"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/Question.java",
    "chars": 640,
    "preview": "package Q7_04_Parking_Lot;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\npublic class Question {\r\n\r\n\t/**\r\n\t * @param args\r\n\t"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/Vehicle.java",
    "chars": 839,
    "preview": "package Q7_04_Parking_Lot;\r\n\r\nimport java.util.ArrayList;\r\n\r\npublic abstract class Vehicle {\r\n\tprotected ArrayList<Parki"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_04_Parking_Lot/VehicleSize.java",
    "chars": 96,
    "preview": "package Q7_04_Parking_Lot;\r\n\r\npublic enum VehicleSize {\r\n\tMotorcycle, \r\n\tCompact, \r\n\tLarge,\r\n}\r\n"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_05_Online_Book_Reader/Book.java",
    "chars": 457,
    "preview": "package Q7_05_Online_Book_Reader;\r\n\r\npublic class Book {\r\n\tprivate int bookId;\r\n\tprivate String details;\t\r\n\t\r\n\tpublic Bo"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_05_Online_Book_Reader/Display.java",
    "chars": 825,
    "preview": "package Q7_05_Online_Book_Reader;\r\n\r\npublic class Display {\r\n\tprivate Book activeBook;\r\n\tprivate User activeUser;\r\n\tpriv"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_05_Online_Book_Reader/Library.java",
    "chars": 585,
    "preview": "package Q7_05_Online_Book_Reader;\r\n\r\nimport java.util.HashMap;\r\n\r\npublic class Library {\r\n\r\n\tprivate HashMap<Integer, Bo"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_05_Online_Book_Reader/OnlineReaderSystem.java",
    "chars": 860,
    "preview": "package Q7_05_Online_Book_Reader;\r\n\r\npublic class OnlineReaderSystem {\r\n\tprivate Library library;\r\n\tprivate UserManager "
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_05_Online_Book_Reader/User.java",
    "chars": 695,
    "preview": "package Q7_05_Online_Book_Reader;\r\n\r\npublic class User {\r\n\tprivate int userId;\r\n\tprivate String details;\r\n\tprivate int a"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_05_Online_Book_Reader/UserManager.java",
    "chars": 618,
    "preview": "package Q7_05_Online_Book_Reader;\r\n\r\nimport java.util.HashMap;\r\n\r\npublic class UserManager {\r\n\tprivate HashMap<Integer, "
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_06_Jigsaw/Edge.java",
    "chars": 906,
    "preview": "package Q7_06_Jigsaw;\n\npublic class Edge {\t\n\tprivate Shape shape;\n\tprivate String code; // used to mock how pieces would"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_06_Jigsaw/Orientation.java",
    "chars": 308,
    "preview": "package Q7_06_Jigsaw;\n\npublic enum Orientation {\n\tLEFT, TOP, RIGHT, BOTTOM; // Should stay in this order \n\t\n\tpublic Orie"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_06_Jigsaw/Piece.java",
    "chars": 2977,
    "preview": "package Q7_06_Jigsaw;\n\nimport java.util.HashMap;\nimport java.util.Map.Entry;\n\npublic class Piece {\n\tprivate final static"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_06_Jigsaw/Puzzle.java",
    "chars": 4284,
    "preview": "package Q7_06_Jigsaw;\n\nimport java.util.LinkedList;\n\npublic class Puzzle {\n\tprivate LinkedList<Piece> pieces; /* Remaini"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_06_Jigsaw/Question.java",
    "chars": 4094,
    "preview": "package Q7_06_Jigsaw;\n\nimport java.util.LinkedList;\nimport java.util.Random;\n\npublic class Question {\n\n\t\n\tpublic static "
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_06_Jigsaw/Shape.java",
    "chars": 209,
    "preview": "package Q7_06_Jigsaw;\n\npublic enum Shape {\n\tINNER, OUTER, FLAT;\n\t\t\n\tpublic Shape getOpposite() {\t\t\n\t\tswitch (this) {\n\t\t\t"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/AddRequest.java",
    "chars": 551,
    "preview": "package Q7_07_Chat_Server;\r\n\r\nimport java.util.Date;\r\n\r\npublic class AddRequest {\r\n\tprivate User fromUser;\r\n\tprivate Use"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/Conversation.java",
    "chars": 455,
    "preview": "package Q7_07_Chat_Server;\r\n\r\nimport java.util.ArrayList;\r\n\r\npublic abstract class Conversation {\r\n\tprotected ArrayList<"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/GroupChat.java",
    "chars": 235,
    "preview": "package Q7_07_Chat_Server;\r\n\r\npublic class GroupChat extends Conversation {\r\n\tpublic void removeParticipant(User user) {"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/Message.java",
    "chars": 334,
    "preview": "package Q7_07_Chat_Server;\r\n\r\nimport java.util.Date;\r\n\r\npublic class Message {\r\n\tprivate String content;\r\n\tprivate Date "
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/PrivateChat.java",
    "chars": 420,
    "preview": "package Q7_07_Chat_Server;\r\n\r\npublic class PrivateChat extends Conversation {\r\n\tpublic PrivateChat(User user1, User user"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/RequestStatus.java",
    "chars": 97,
    "preview": "package Q7_07_Chat_Server;\r\n\r\npublic enum RequestStatus {\r\n\tUnread, Read, Accepted, Rejected\r\n}\r\n"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/System.java",
    "chars": 58,
    "preview": "package Q7_07_Chat_Server;\r\n\r\npublic class System {\r\n\r\n}\r\n"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/User.java",
    "chars": 2915,
    "preview": "package Q7_07_Chat_Server;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.Date;\r\nimport java.util.HashMap;\r\n\r\npublic c"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/UserManager.java",
    "chars": 1775,
    "preview": "package Q7_07_Chat_Server;\r\n\r\nimport java.util.Date;\r\nimport java.util.HashMap;\r\n\r\n/* UserManager serves as the central "
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/UserStatus.java",
    "chars": 364,
    "preview": "package Q7_07_Chat_Server;\r\n\r\npublic class UserStatus {\r\n\t private String message;\r\n\t private UserStatusType type;\r\n\t pu"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_07_Chat_Server/UserStatusType.java",
    "chars": 102,
    "preview": "package Q7_07_Chat_Server;\r\n\r\npublic enum UserStatusType {\r\n\tOffline, Away, Idle, Available, Busy\r\n}\r\n"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_08_Othello/Automator.java",
    "chars": 2453,
    "preview": "package Q7_08_Othello;\r\n\r\nimport java.util.ArrayList;\r\n\r\nimport CtCILibrary.AssortedMethods;\r\n\r\n/* A helper class to aut"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_08_Othello/Board.java",
    "chars": 3769,
    "preview": "package Q7_08_Othello;\r\n\r\npublic class Board {\r\n\tprivate int blackCount = 0;\r\n\tprivate int whiteCount = 0;\r\n\tprivate Pie"
  },
  {
    "path": "Java/Ch 07. Object-Oriented Design/Q7_08_Othello/Color.java",
    "chars": 65,
    "preview": "package Q7_08_Othello;\r\n\r\npublic enum Color {\r\n\tWhite, Black\r\n}\r\n"
  }
]

// ... and 392 more files (download for full content)

About this extraction

This page contains the full source code of the careercup/CtCI-6th-Edition GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 592 files (76.0 MB), approximately 251.8k tokens, and a symbol index with 2741 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!