├── docs ├── SDI.pdf ├── Big-O.pdf ├── Devops Interview.pdf ├── QA Engineer Interview.pdf └── SQL-vs-NoSQL-Databases.pdf ├── src ├── main │ └── java │ │ ├── hackerrank │ │ ├── search │ │ │ ├── SwapNodesAlgo.java │ │ │ └── HashTablesIceCreamParlor.java │ │ ├── warm_up_challenges │ │ │ ├── SalesByMatch.md │ │ │ ├── CountingValleys.md │ │ │ ├── RepeatedString.java │ │ │ ├── CountingValleys.java │ │ │ ├── SalesByMatch.java │ │ │ ├── JumpingOnTheClouds.java │ │ │ └── JumpingOnTheClouds.md │ │ ├── string_manipulation │ │ │ ├── AlternatingCharacters.java │ │ │ ├── MakingAnagram.java │ │ │ ├── CommonChild.java │ │ │ ├── SpecialStringAgain.java │ │ │ └── SherlockAndValidString.java │ │ ├── greedy_algorithms │ │ │ ├── GreedyFlorist.java │ │ │ ├── MaxMin.java │ │ │ ├── MinimumAbsoluteDifferenceInAnArray.java │ │ │ ├── LuckBalance.java │ │ │ └── ReverseShuffleMerge.java │ │ ├── dictionaries_and_hashmaps │ │ │ ├── TwoStrings.java │ │ │ ├── CountTriplets.java │ │ │ ├── RansomNote.java │ │ │ ├── SherLockAndAnagrams.java │ │ │ └── FrequencyQueries.java │ │ ├── dynamic_programming │ │ │ └── MaxArraySum.java │ │ ├── sorting │ │ │ ├── Comparator.java │ │ │ ├── MarkAndToys.java │ │ │ ├── BubbleSort.java │ │ │ └── MergeSortCountingInversions.java │ │ └── arrays │ │ │ ├── ArraysLeftRotation.java │ │ │ ├── NewYearChaos.java │ │ │ ├── TwoDArrayDS.java │ │ │ └── MinimumSwapsTwo.java │ │ ├── dsa │ │ ├── mathematics_and_number_theory │ │ │ ├── PrimeNumbers.java │ │ │ ├── GCD.java │ │ │ ├── TrailingZeroInFactorial.java │ │ │ ├── PalindromeNumbers.java │ │ │ ├── SieveOfEratoSthenes.java │ │ │ └── Factorial.java │ │ └── bit_manipulation │ │ │ ├── NonRepeatingElementInArray.java │ │ │ ├── TwoNonRepeatingElementInArray.java │ │ │ └── NonRepeatingElementInArrayElementsRepeatingKthTime.java │ │ ├── interviews │ │ ├── remotebase │ │ │ ├── resources │ │ │ │ ├── network.png │ │ │ │ ├── domain_test.png │ │ │ │ ├── hr_screening.png │ │ │ │ ├── final_interview.png │ │ │ │ └── problem_solving.png │ │ │ ├── coding_challenge_hackerrank │ │ │ │ ├── resources │ │ │ │ │ ├── TeamFormation.png │ │ │ │ │ └── MaximizeTheValue.png │ │ │ │ └── question │ │ │ │ │ ├── Question2.java │ │ │ │ │ ├── Question4.java │ │ │ │ │ ├── Question1.java │ │ │ │ │ └── Question3.java │ │ │ ├── Readme.md │ │ │ └── live_coding_interview │ │ │ │ ├── Readme.md │ │ │ │ └── questions │ │ │ │ └── Question1.java │ │ ├── amazon │ │ │ ├── coding_challenge_hackerrank │ │ │ │ ├── resources │ │ │ │ │ ├── question2_example.png │ │ │ │ │ └── question3_example.png │ │ │ │ └── questions │ │ │ │ │ ├── Question3.java │ │ │ │ │ ├── Question2.java │ │ │ │ │ ├── Question4.java │ │ │ │ │ └── Question1.java │ │ │ └── Readme.md │ │ ├── avenue_code │ │ │ ├── coding_challenge_hackerrank │ │ │ │ └── resources │ │ │ │ │ ├── section1 │ │ │ │ │ ├── section1_1.png │ │ │ │ │ ├── section1_2.png │ │ │ │ │ ├── section1_3.png │ │ │ │ │ ├── section1_4.png │ │ │ │ │ ├── section1_5.png │ │ │ │ │ ├── section1_6.png │ │ │ │ │ ├── section1_7.png │ │ │ │ │ ├── section1_8.png │ │ │ │ │ ├── section1_9.png │ │ │ │ │ ├── section1_10.png │ │ │ │ │ ├── section1_collaborator1.png │ │ │ │ │ └── section1_collaborator2.png │ │ │ │ │ ├── section2 │ │ │ │ │ ├── question1 │ │ │ │ │ │ ├── section2_1.png │ │ │ │ │ │ ├── section2_2.png │ │ │ │ │ │ └── section2_3.png │ │ │ │ │ ├── question2 │ │ │ │ │ │ └── section2_1.png │ │ │ │ │ └── section2_collaborator1.png │ │ │ │ │ ├── section3 │ │ │ │ │ ├── question1 │ │ │ │ │ │ ├── section3_1.png │ │ │ │ │ │ └── section3_2.png │ │ │ │ │ ├── question2 │ │ │ │ │ │ └── section3_1.png │ │ │ │ │ └── section3_collaborator1.png │ │ │ │ │ └── section4 │ │ │ │ │ ├── question1 │ │ │ │ │ ├── section4_1.png │ │ │ │ │ └── section4_2.png │ │ │ │ │ ├── question2 │ │ │ │ │ └── section4_1.png │ │ │ │ │ └── section4_collaborator1.png │ │ │ └── Readme.md │ │ ├── teamapt │ │ │ ├── online_assessment │ │ │ │ ├── resources │ │ │ │ │ └── Report_TeamApt_Back-End_Developer_Hiring_Test.pdf │ │ │ │ ├── questions │ │ │ │ │ ├── Question1.java │ │ │ │ │ └── Question2.java │ │ │ │ └── Readme.md │ │ │ └── Readme.md │ │ ├── aurora_solutions │ │ │ ├── Readme.md │ │ │ └── coding_challenge_coderbyte │ │ │ │ ├── question │ │ │ │ ├── Question2.java │ │ │ │ ├── Question3.java │ │ │ │ ├── Question4.java │ │ │ │ └── Question1.java │ │ │ │ └── Readme.md │ │ ├── glovo │ │ │ ├── live_coding_interview │ │ │ │ ├── questions │ │ │ │ │ ├── Question2.java │ │ │ │ │ └── Question1.java │ │ │ │ └── Readme.md │ │ │ └── Readme.md │ │ └── callsign │ │ │ └── live_coding_interview │ │ │ ├── questions │ │ │ └── Question1.java │ │ │ └── Readme.md │ │ ├── leetcode │ │ ├── ClimbingStairs.java │ │ ├── RemoveDuplicatesFromSortedArray.java │ │ ├── Sqrt.java │ │ ├── MergeSortedArray.java │ │ ├── TwoSum.java │ │ ├── PlusOne.java │ │ ├── LongestCommonPrefix.java │ │ ├── RomanToInteger.java │ │ ├── MergeTwoSortedLists.java │ │ ├── ValidParentheses.java │ │ └── BinaryTreeInorderTraversal.java │ │ ├── utils │ │ └── CaptureOutput.java │ │ └── amazon_questions │ │ ├── interviewbit │ │ ├── MajorityElement.java │ │ ├── GasStation.java │ │ ├── LongestIncreasingSubsequence.java │ │ ├── MinimumSumPathInMatrix.java │ │ ├── WaysToDecode.java │ │ └── MaxProductSubarray.java │ │ ├── KLargestOrSmallestElements.java │ │ ├── MissingNumberInArray.java │ │ ├── MergeTwoSortedLinkedList.java │ │ ├── SumOfTwoIntegersInArrayEqualsGivenValue.java │ │ └── PythagoreanTriplet.java └── test │ └── java │ ├── leetcode │ ├── RomanToIntegerTest.java │ ├── LongestCommonPrefixTest.java │ ├── RemoveDuplicatesFromSortedArrayTest.java │ ├── TwoSumTest.java │ ├── ClimbingStairsTest.java │ ├── ValidParenthesesTest.java │ ├── SqrtTest.java │ ├── PlusOneTest.java │ ├── BinaryTreeInorderTraversalTest.java │ ├── MergeSortedArrayTest.java │ └── MergeTwoSortedListsTest.java │ ├── amazon_questions │ ├── interviewbit │ │ ├── MinimumSumPathInMatrixTest.java │ │ ├── GasStationTest.java │ │ ├── LongestIncreasingSubsequenceTest.java │ │ ├── WaysToDecodeTest.java │ │ ├── MaxProductSubarrayTest.java │ │ ├── MajorityElementTest.java │ │ ├── DistributeCandyTest.java │ │ └── ReversePolishNotationTest.java │ ├── SumOfTwoIntegersInArrayEqualsGivenValueTest.java │ ├── PythagoreanTripletTest.java │ ├── MissingNumberInArrayTest.java │ ├── MergeTwoSortedLinkedListTest.java │ └── KLargestOrSmallestElementsTest.java │ ├── dsa │ ├── mathematics_and_number_theory │ │ ├── GCDTest.java │ │ ├── PalindromeNumbersTest.java │ │ ├── TrailingZeroInFactorialTest.java │ │ ├── SieveOfEratoSthenesTest.java │ │ └── FactorialTest.java │ └── bit_manipulation │ │ ├── NonRepeatingElementInArrayTest.java │ │ ├── TwoNonRepeatingElementInArrayTest.java │ │ └── NonRepeatingElementInArrayElementsRepeatingKthTimeTest.java │ ├── hackerrank │ ├── warm_up_challenges │ │ ├── SalesByMatchTest.java │ │ ├── CountingValleysTest.java │ │ ├── RepeatedStringTest.java │ │ └── JumpingOnTheCloudsTest.java │ ├── sorting │ │ ├── BubbleSortTest.java │ │ ├── MarkAndToysTest.java │ │ ├── FraudulentActivityNotificationsTest.java │ │ ├── ComparatorTest.java │ │ └── MergeSortCountingInversionsTest.java │ ├── string_manipulation │ │ ├── CommonChildTest.java │ │ ├── SpecialStringAgainTest.java │ │ ├── SherlockAndValidStringTest.java │ │ ├── MakingAnagramTest.java │ │ └── AlternatingCharactersTest.java │ ├── dynamic_programming │ │ └── MaxArraySumTest.java │ ├── greedy_algorithms │ │ ├── GreedyFloristTest.java │ │ ├── MaxMinTest.java │ │ ├── ReverseShuffleMergeTest.java │ │ ├── MinimumAbsoluteDifferenceInAnArrayTest.java │ │ └── LuckBalanceTest.java │ ├── arrays │ │ ├── MinimumSwapsTwoTest.java │ │ ├── NewYearChaosTest.java │ │ ├── ArraysLeftRotationTest.java │ │ ├── TwoDArrayDSTest.java │ │ └── ArrayManipulationTest.java │ ├── dictionaries_and_hashmaps │ │ ├── CountTripletsTest.java │ │ ├── TwoStringsTest.java │ │ ├── SherLockAndAnagramsTest.java │ │ ├── RansomNoteTest.java │ │ └── FrequencyQueriesTest.java │ └── search │ │ └── HashTablesIceCreamParlorTest.java │ └── interviews │ ├── amazon │ └── coding_challenge_hackerrank │ │ └── questions │ │ ├── Question1Test.java │ │ ├── Question3Test.java │ │ ├── Question4Test.java │ │ └── Question2Test.java │ ├── glovo │ └── live_coding_interview │ │ └── questions │ │ ├── Question1Test.java │ │ └── Question2Test.java │ ├── callsign │ └── live_coding_interview │ │ └── questions │ │ └── Question1Test.java │ ├── aurora_solutions │ └── coding_challenge_coderbyte │ │ └── question │ │ ├── Question2Test.java │ │ ├── Question3Test.java │ │ ├── Question1Test.java │ │ └── Question4Test.java │ ├── remotebase │ ├── coding_challenge_hackerrank │ │ └── questions │ │ │ ├── Question3Test.java │ │ │ ├── Question1Test.java │ │ │ ├── Question4Test.java │ │ │ └── Question2Test.java │ └── live_coding_interview │ │ └── questions │ │ └── Question1Test.java │ ├── avenue_code │ └── coding_challenge_hackerrank │ │ └── questions │ │ ├── Section2Question2Test.java │ │ └── Section2Question1Test.java │ └── teamapt │ └── online_assessment │ └── questions │ ├── Question1Test.java │ └── Question2Test.java ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE └── pom.xml /docs/SDI.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/docs/SDI.pdf -------------------------------------------------------------------------------- /docs/Big-O.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/docs/Big-O.pdf -------------------------------------------------------------------------------- /docs/Devops Interview.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/docs/Devops Interview.pdf -------------------------------------------------------------------------------- /src/main/java/hackerrank/search/SwapNodesAlgo.java: -------------------------------------------------------------------------------- 1 | package hackerrank.search; 2 | 3 | public class SwapNodesAlgo { 4 | } 5 | -------------------------------------------------------------------------------- /docs/QA Engineer Interview.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/docs/QA Engineer Interview.pdf -------------------------------------------------------------------------------- /docs/SQL-vs-NoSQL-Databases.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/docs/SQL-vs-NoSQL-Databases.pdf -------------------------------------------------------------------------------- /src/main/java/dsa/mathematics_and_number_theory/PrimeNumbers.java: -------------------------------------------------------------------------------- 1 | package dsa.mathematics_and_number_theory; 2 | 3 | public class PrimeNumbers { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/resources/network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/remotebase/resources/network.png -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/resources/domain_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/remotebase/resources/domain_test.png -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/resources/hr_screening.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/remotebase/resources/hr_screening.png -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/resources/final_interview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/remotebase/resources/final_interview.png -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/resources/problem_solving.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/remotebase/resources/problem_solving.png -------------------------------------------------------------------------------- /src/main/java/interviews/amazon/coding_challenge_hackerrank/resources/question2_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/amazon/coding_challenge_hackerrank/resources/question2_example.png -------------------------------------------------------------------------------- /src/main/java/interviews/amazon/coding_challenge_hackerrank/resources/question3_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/amazon/coding_challenge_hackerrank/resources/question3_example.png -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/coding_challenge_hackerrank/resources/TeamFormation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/remotebase/coding_challenge_hackerrank/resources/TeamFormation.png -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/coding_challenge_hackerrank/resources/MaximizeTheValue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/remotebase/coding_challenge_hackerrank/resources/MaximizeTheValue.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_1.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_2.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_3.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_4.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_5.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_6.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_7.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_8.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_9.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_10.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section2/question1/section2_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section2/question1/section2_1.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section2/question1/section2_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section2/question1/section2_2.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section2/question1/section2_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section2/question1/section2_3.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section2/question2/section2_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section2/question2/section2_1.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section3/question1/section3_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section3/question1/section3_1.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section3/question1/section3_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section3/question1/section3_2.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section3/question2/section3_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section3/question2/section3_1.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section4/question1/section4_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section4/question1/section4_1.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section4/question1/section4_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section4/question1/section4_2.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section4/question2/section4_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section4/question2/section4_1.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_collaborator1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_collaborator1.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_collaborator2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section1/section1_collaborator2.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section2/section2_collaborator1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section2/section2_collaborator1.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section3/section3_collaborator1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section3/section3_collaborator1.png -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section4/section4_collaborator1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/avenue_code/coding_challenge_hackerrank/resources/section4/section4_collaborator1.png -------------------------------------------------------------------------------- /src/main/java/interviews/teamapt/online_assessment/resources/Report_TeamApt_Back-End_Developer_Hiring_Test.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammaralii/interview-preparation-kit/HEAD/src/main/java/interviews/teamapt/online_assessment/resources/Report_TeamApt_Back-End_Developer_Hiring_Test.pdf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea 3 | pom.xml.tag 4 | pom.xml.releaseBackup 5 | pom.xml.versionsBackup 6 | pom.xml.next 7 | release.properties 8 | dependency-reduced-pom.xml 9 | buildNumber.properties 10 | .mvn/timing.properties 11 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar 12 | .mvn/wrapper/maven-wrapper.jar 13 | -------------------------------------------------------------------------------- /src/main/java/dsa/mathematics_and_number_theory/GCD.java: -------------------------------------------------------------------------------- 1 | package dsa.mathematics_and_number_theory; 2 | 3 | public class GCD { 4 | public static Integer find(Integer a, Integer b) { 5 | if (a % b == 0) { 6 | return b; 7 | } else { 8 | return find(b, a % b); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/leetcode/RomanToIntegerTest.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class RomanToIntegerTest { 7 | @Test 8 | public void success_countDecreasingRatings_test_0() { 9 | Assert.assertTrue(RomanToInteger.romanToInt("MCMXCIV") == 1994); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/leetcode/LongestCommonPrefixTest.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class LongestCommonPrefixTest { 7 | @Test 8 | public void success_find_test_0() { 9 | Assert.assertEquals(LongestCommonPrefix.find(new String[]{"flower","flow","flight"}), "fl"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/leetcode/RemoveDuplicatesFromSortedArrayTest.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class RemoveDuplicatesFromSortedArrayTest { 7 | @Test 8 | public void success_countDecreasingRatings_test_0() { 9 | Assert.assertEquals(RemoveDuplicatesFromSortedArray.removeDuplicates(new int[]{1,1,2,2,3,3}), 3); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/leetcode/TwoSumTest.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class TwoSumTest { 7 | @Test 8 | public void success_containingAnyCombination_test_0() { 9 | int[] result = TwoSum.twoSum(new int[]{3,2,4}, 6); 10 | Assert.assertEquals(result[0], 1); 11 | Assert.assertEquals(result[1], 2); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/warm_up_challenges/SalesByMatch.md: -------------------------------------------------------------------------------- 1 | There is a large pile of socks that must be paired by color. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are. 2 | 3 | **Example** 4 | 5 | n=7 6 | 7 | ar=[1,2,1,2,1,3,2] 8 | 9 | There is one pair of color and one of color . There are three odd socks left, one of each color. The number of pairs is **2**. -------------------------------------------------------------------------------- /src/test/java/amazon_questions/interviewbit/MinimumSumPathInMatrixTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class MinimumSumPathInMatrixTest { 7 | 8 | @Test 9 | public void success_find_test_0() { 10 | int [][]grid = {{1,3,2},{4,3,1},{5,6,1}}; 11 | Assert.assertEquals(MinimumSumPathInMatrix.find(grid), 8); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/leetcode/ClimbingStairs.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | public class ClimbingStairs { 4 | public static int climbStairs(int n) { 5 | if (n <= 2) 6 | return n; 7 | 8 | int a = 1; 9 | int b = 2; 10 | 11 | for (int i = 3; i <= n; i++) { 12 | int sum = a + b; 13 | a = b; 14 | b = sum; 15 | } 16 | return b; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/amazon_questions/interviewbit/GasStationTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class GasStationTest { 9 | @Test 10 | public void success_canCompleteCircuit_test_0() { 11 | Assert.assertTrue(GasStation.canCompleteCircuit(Arrays.asList(1, 2), Arrays.asList(2, 1)) == 1); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/leetcode/RemoveDuplicatesFromSortedArray.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | public class RemoveDuplicatesFromSortedArray { 4 | public static int removeDuplicates(int[] nums) { 5 | int index = 1; 6 | for (int i = 1; i < nums.length; i++) { 7 | if (nums[i-1] != nums[i]){ 8 | nums[index] = nums[i]; 9 | index++; 10 | } 11 | } 12 | return index; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/dsa/mathematics_and_number_theory/GCDTest.java: -------------------------------------------------------------------------------- 1 | package dsa.mathematics_and_number_theory; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class GCDTest { 7 | @Test 8 | public void success_find_test_0() { 9 | Assert.assertTrue(GCD.find(24, 60) == 12); 10 | } 11 | 12 | @Test 13 | public void success_find_test_1() { 14 | Assert.assertTrue(GCD.find(100, 1000) == 100); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/amazon_questions/interviewbit/LongestIncreasingSubsequenceTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class LongestIncreasingSubsequenceTest { 9 | @Test 10 | public void success_find_test_0() { 11 | Assert.assertTrue(LongestIncreasingSubsequence.lis(Arrays.asList(10, 22, 9, 33, 21, 50, 41, 60)) == 5); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/interviews/aurora_solutions/Readme.md: -------------------------------------------------------------------------------- 1 | ## Java Engineer | Back-End Developer 2 | ## Coding Assessment On Hackerrank 3 | **Time**: 4 hours, **Questions**: Consist of 4 sections, 1st section contains 10 other contains 1 4 | 5 | Please check the [coding_challenge_hac](coding_challenge_coderbyte) folder to check list of questions asked in previous Coding Assessment 6 | 7 | ## Technical Interview 8 | **Time**: 30 min 9 | 10 | Good luck with the preparation ! 11 | -------------------------------------------------------------------------------- /src/test/java/amazon_questions/interviewbit/WaysToDecodeTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class WaysToDecodeTest { 7 | @Test 8 | public void success_find_test_0() { 9 | Assert.assertTrue(WaysToDecode.find("12") == 2); 10 | } 11 | 12 | @Test 13 | public void success_find_test_1() { 14 | Assert.assertTrue(WaysToDecode.find("1234") == 3); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/string_manipulation/AlternatingCharacters.java: -------------------------------------------------------------------------------- 1 | package hackerrank.string_manipulation; 2 | 3 | public class AlternatingCharacters { 4 | public static int alternatingCharacters(String s) { 5 | int count = 0; 6 | char[] sChar = s.toCharArray(); 7 | for(int i=1;i list = Arrays.asList(1,2,1,2,1,3,2); 13 | Assert.assertEquals(SalesByMatch.sockMerchant(list.size(),list), 2); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/dsa/mathematics_and_number_theory/PalindromeNumbersTest.java: -------------------------------------------------------------------------------- 1 | package dsa.mathematics_and_number_theory; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class PalindromeNumbersTest { 7 | @Test 8 | public void success_find_test_0() { 9 | Assert.assertTrue(PalindromeNumbers.find(404)); 10 | } 11 | 12 | @Test 13 | public void failure_find_test_1() { 14 | Assert.assertFalse(PalindromeNumbers.find(521)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/dsa/mathematics_and_number_theory/TrailingZeroInFactorial.java: -------------------------------------------------------------------------------- 1 | package dsa.mathematics_and_number_theory; 2 | 3 | /** 4 | * Factorial of a number
5 | * Find the factorial of 5, 10 and 1000 6 | */ 7 | public class TrailingZeroInFactorial { 8 | public static Integer find(Integer n) { 9 | Integer result = 0; 10 | for (int i = 5; i <= n; i = i * 5) { 11 | result += n / i; 12 | } 13 | System.out.println("Result is: " + result); 14 | return result; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/greedy_algorithms/GreedyFlorist.java: -------------------------------------------------------------------------------- 1 | package hackerrank.greedy_algorithms; 2 | 3 | import java.util.Arrays; 4 | 5 | public class GreedyFlorist { 6 | public static int getMinimumCost(int k, int[] c) { 7 | Arrays.sort(c); 8 | int cost = 0; 9 | int previousPurchaseCount = 0; 10 | for (int i = c.length - 1; i >= 0; i--) { 11 | cost += (1 + (previousPurchaseCount / k)) * c[i]; 12 | previousPurchaseCount++; 13 | } 14 | return cost; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/leetcode/Sqrt.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | public class Sqrt { 4 | public static int mySqrt(int x) { 5 | if (x < 2) 6 | return x; 7 | int left = 1, right = x/2; 8 | while (true) { 9 | int mid = left + (right - left) / 2; 10 | if (mid > x / mid) { 11 | right = mid - 1; 12 | } else { 13 | if (mid + 1 > x / (mid + 1)) 14 | return mid; 15 | left = mid + 1; 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/dictionaries_and_hashmaps/TwoStrings.java: -------------------------------------------------------------------------------- 1 | package hackerrank.dictionaries_and_hashmaps; 2 | 3 | import java.util.LinkedHashSet; 4 | import java.util.Set; 5 | 6 | public class TwoStrings { 7 | public static String twoStrings(String s1, String s2) { 8 | Set set = new LinkedHashSet<>(); 9 | s1.chars().forEach(e -> set.add((char) e)); 10 | for (char c: set){ 11 | if(s1.indexOf(c)>-1 && s2.indexOf(c)>-1) 12 | return "YES"; 13 | } 14 | return "NO"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/leetcode/MergeSortedArray.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | public class MergeSortedArray { 4 | public static void merge(int[] nums1, int m, int[] nums2, int n) { 5 | int i = m - 1, j = n - 1, k = m + n - 1; 6 | while (i >= 0 && j >= 0) { 7 | if (nums1[i] < nums2[j]) { 8 | nums1[k--] = nums2[j--]; 9 | } else { 10 | nums1[k--] = nums1[i--]; 11 | } 12 | } 13 | 14 | while (j >= 0) { 15 | nums1[k--] = nums2[j--]; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/dsa/bit_manipulation/NonRepeatingElementInArrayTest.java: -------------------------------------------------------------------------------- 1 | package dsa.bit_manipulation; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class NonRepeatingElementInArrayTest { 9 | @Test 10 | public void success_find_test_0() { 11 | Assert.assertTrue(NonRepeatingElementInArray.find(Arrays.asList(5,4,1,4,3,5,1)).equals(3)); 12 | } 13 | 14 | @Test 15 | public void success_find_test_1() { 16 | Assert.assertTrue(NonRepeatingElementInArray.find(Arrays.asList(5,5)).equals(0)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/amazon_questions/interviewbit/MaxProductSubarrayTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class MaxProductSubarrayTest { 9 | 10 | @Test 11 | public void success_find_test_0() { 12 | Assert.assertTrue(MaxProductSubarray.find(Arrays.asList(2, 3, -2, 4)) == 6); 13 | } 14 | 15 | @Test 16 | public void success_find_test_1() { 17 | Assert.assertTrue(MaxProductSubarray.find(Arrays.asList(1, -2, -3, 0, 7, -8, -2)) == 112); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/sorting/BubbleSortTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.sorting; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Arrays; 6 | 7 | public class BubbleSortTest { 8 | @Test 9 | public void success_countSwaps_test_0() { 10 | BubbleSort.countSwaps(Arrays.asList(1,2,3)); 11 | } 12 | 13 | @Test 14 | public void success_countSwaps_test_1() { 15 | BubbleSort.countSwaps(Arrays.asList(3,2,1)); 16 | } 17 | 18 | @Test 19 | public void success_countSwaps_test_2() { 20 | BubbleSort.countSwaps(Arrays.asList(4,2,3,1)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/dsa/bit_manipulation/NonRepeatingElementInArray.java: -------------------------------------------------------------------------------- 1 | package dsa.bit_manipulation; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * only non repeating element in array
7 | * Find the only non repeating element in array, where every element repeat twice 8 | */ 9 | public class NonRepeatingElementInArray { 10 | public static Integer find(List list) { 11 | Integer result = list.get(0) ^ list.get(1); 12 | for (int i = 2; i < list.size(); i++) { 13 | result = result ^ list.get(i); 14 | } 15 | return result; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/dsa/mathematics_and_number_theory/PalindromeNumbers.java: -------------------------------------------------------------------------------- 1 | package dsa.mathematics_and_number_theory; 2 | 3 | public class PalindromeNumbers { 4 | public static boolean find(Integer n) { 5 | Integer actualNumber = n; 6 | StringBuilder result = new StringBuilder(); 7 | while (n != 0) { 8 | Integer temp = n % 10; 9 | result.append(temp); 10 | n = n / 10; 11 | } 12 | if (Integer.valueOf(result.toString()).equals(actualNumber)){ 13 | return true; 14 | } 15 | return false; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/interviews/amazon/coding_challenge_hackerrank/questions/Question1Test.java: -------------------------------------------------------------------------------- 1 | package interviews.amazon.coding_challenge_hackerrank.questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class Question1Test { 7 | @Test 8 | public void success_maxSetSize_test_0() { 9 | Assert.assertEquals(Question1.maxSetSize(new int[]{3, 9, 4, 2, 16}), 3); 10 | } 11 | 12 | @Test 13 | public void success_maxSetSize_test_1() { 14 | Assert.assertEquals(Question1.maxSetSize(new int[]{2, 4, 5, 25, 26, 125, 16, 625, 390625}), 4); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/amazon_questions/interviewbit/MajorityElementTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class MajorityElementTest { 9 | @Test 10 | public void success_majorityElement_test_0() { 11 | Assert.assertTrue(MajorityElement.majorityElement(Arrays.asList(2,1,2)) == 2); 12 | } 13 | 14 | @Test 15 | public void success_majorityElement_test_1() { 16 | Assert.assertTrue(MajorityElement.majorityElement(Arrays.asList(2,1,2,1,3,4,4,3,1)) == 1); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/amazon_questions/interviewbit/DistributeCandyTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class DistributeCandyTest { 9 | @Test 10 | public void success_distribute_test_0() { 11 | Assert.assertTrue(DistributeCandy.distribute(Arrays.asList(10, 12, 1, 4, 11, 7, 9, 17, 6, 2, 23)) == 20); 12 | } 13 | 14 | @Test 15 | public void success_distribute_test_1() { 16 | Assert.assertTrue(DistributeCandy.distribute(Arrays.asList(1, 5, 2, 1)) == 7); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/dsa/mathematics_and_number_theory/SieveOfEratoSthenes.java: -------------------------------------------------------------------------------- 1 | package dsa.mathematics_and_number_theory; 2 | 3 | import java.util.Arrays; 4 | 5 | public class SieveOfEratoSthenes { 6 | public static boolean[] find(Integer n) { 7 | boolean isPrime[] = new boolean[n + 1]; 8 | Arrays.fill(isPrime, true); 9 | isPrime[0] = false; 10 | isPrime[1] = false; 11 | for (int i = 2; i * i <= n; i++) { 12 | for (int j = 2 * i; j <= n; j += i) { 13 | isPrime[j] = false; 14 | } 15 | } 16 | return isPrime; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/greedy_algorithms/MaxMin.java: -------------------------------------------------------------------------------- 1 | package hackerrank.greedy_algorithms; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | 6 | public class MaxMin { 7 | public static int maxMin(int k, List arr) { 8 | arr = arr.stream().sorted().collect(Collectors.toList()); 9 | int min = Integer.MAX_VALUE; 10 | int i = 0; 11 | for (i = 0; (i + k - 1) < arr.size(); i++) { 12 | if (arr.get(i + k - 1) - arr.get(i) < min) 13 | min = arr.get(i + k - 1) - arr.get(i); 14 | } 15 | return min; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/amazon_questions/interviewbit/ReversePolishNotationTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class ReversePolishNotationTest { 7 | @Test 8 | public void success_find_test_0() { 9 | Assert.assertTrue(ReversePolishNotation.find(new String[]{"5","3","+","2","/"}) == 4); 10 | } 11 | 12 | @Test 13 | public void success_find_test_1() { 14 | Assert.assertTrue(ReversePolishNotation.find(new String[]{"10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"}) == 22); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/dynamic_programming/MaxArraySum.java: -------------------------------------------------------------------------------- 1 | package hackerrank.dynamic_programming; 2 | 3 | public class MaxArraySum { 4 | public static int maxSubsetSum(int[] arr) { 5 | if (arr.length == 0) { 6 | return 0; 7 | } 8 | arr[0] = Math.max(0, arr[0]); 9 | if (arr.length == 1) { 10 | return arr[0]; 11 | } 12 | arr[1] = Math.max(arr[0], arr[1]); 13 | for (int i = 2; i < arr.length; i++) { 14 | arr[i] = Math.max(arr[i - 1], arr[i] + arr[i - 2]); 15 | } 16 | return arr[arr.length - 1]; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/dsa/bit_manipulation/TwoNonRepeatingElementInArrayTest.java: -------------------------------------------------------------------------------- 1 | package dsa.bit_manipulation; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class TwoNonRepeatingElementInArrayTest { 9 | @Test 10 | public void success_find_test_0() { 11 | Assert.assertTrue(TwoNonRepeatingElementInArray.find(Arrays.asList(5,4,1,4,3,5,1,2)).equals("3 2")); 12 | } 13 | 14 | @Test 15 | public void success_find_test_1() { 16 | Assert.assertTrue(TwoNonRepeatingElementInArray.find(Arrays.asList(5,5,3,4)).equals("3 4")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/sorting/Comparator.java: -------------------------------------------------------------------------------- 1 | package hackerrank.sorting; 2 | 3 | public class Comparator implements java.util.Comparator { 4 | @Override 5 | public int compare(Player a, Player b) { 6 | if (a.score < b.score) { 7 | return 1; 8 | } else if (a.score > b.score) { 9 | return -1; 10 | } else { 11 | return a.name.compareTo(b.name); 12 | } 13 | } 14 | } 15 | 16 | class Player { 17 | String name; 18 | int score; 19 | 20 | Player(String name, int score) { 21 | this.name = name; 22 | this.score = score; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/leetcode/TwoSum.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class TwoSum { 7 | public static int[] twoSum(int[] nums, int target) { 8 | int n = nums.length; 9 | 10 | Map numsMap = new HashMap<>(); 11 | 12 | for(int i=0;i= 0; i--) { 6 | if (digits[i] < 9) { 7 | digits[i]++; 8 | break; 9 | } 10 | digits[i] = 0; 11 | } 12 | 13 | //Added if for corner case for {9,9,9} 14 | if (digits[0] == 0) { 15 | int[] newDigits = new int[digits.length + 1]; 16 | newDigits[0] = 1; 17 | return newDigits; 18 | } else { 19 | return digits; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/utils/CaptureOutput.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.PrintStream; 5 | 6 | public class CaptureOutput { 7 | public static String captureStandardOutput(Runnable runnable) { 8 | final ByteArrayOutputStream baos = new ByteArrayOutputStream(); 9 | final PrintStream ps = new PrintStream(baos); 10 | final PrintStream old = System.out; 11 | System.setOut(ps); 12 | try { 13 | runnable.run(); 14 | } finally { 15 | System.out.flush(); 16 | System.setOut(old); 17 | } 18 | return baos.toString(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/interviews/amazon/coding_challenge_hackerrank/questions/Question3Test.java: -------------------------------------------------------------------------------- 1 | package interviews.amazon.coding_challenge_hackerrank.questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class Question3Test { 9 | @Test 10 | public void success_countDecreasingRatings_test_0() { 11 | Assert.assertTrue(Question3.countDecreasingRatings(Arrays.asList(2,1,3)).equals(4)); 12 | } 13 | 14 | @Test 15 | public void success_countDecreasingRatings_test_1() { 16 | Assert.assertTrue(Question3.countDecreasingRatings(Arrays.asList(4,3,5,4,3)).equals(9)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/dsa/mathematics_and_number_theory/TrailingZeroInFactorialTest.java: -------------------------------------------------------------------------------- 1 | package dsa.mathematics_and_number_theory; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class TrailingZeroInFactorialTest { 7 | @Test 8 | public void success_find_test_0() { 9 | Assert.assertTrue(TrailingZeroInFactorial.find(5) == 1); 10 | } 11 | 12 | @Test 13 | public void success_find_test_1() { 14 | Assert.assertTrue(TrailingZeroInFactorial.find(10) == 2); 15 | } 16 | 17 | @Test 18 | public void success_find_test_2() { 19 | Assert.assertTrue(TrailingZeroInFactorial.find(1000) == 249); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/string_manipulation/CommonChildTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.string_manipulation; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class CommonChildTest { 7 | @Test 8 | public void success_commonChild_test_0() { 9 | Assert.assertEquals(CommonChild.commonChild("HARRY","SALLY"), 2); 10 | } 11 | 12 | @Test 13 | public void success_commonChild_test_1() { 14 | Assert.assertEquals(CommonChild.commonChild("AA","BB"), 0); 15 | } 16 | 17 | @Test 18 | public void success_commonChild_test_2() { 19 | Assert.assertEquals(CommonChild.commonChild("SHINCHAN","NOHARAAA"), 3); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/interviews/teamapt/Readme.md: -------------------------------------------------------------------------------- 1 | ## SENIOR BACKEND ENGINEER(JAVA) 2 | 3 | ## Live Coding Session 4 | 5 | ### INSTRUCTION 6 | 7 | Coding session is divided to 4 parts: 8 | 9 | - Problem-Solving(Some coding problem related to DSA) 10 | - Database(Write query according to statement) 11 | - Rest API(Need to write code for rest call and perform some operation) 12 | - MCQS related to LinkedList and Binary Trees 13 | 14 | 15 | Please check the [questions](online_assessment) folder to check list of questions asked in previous live coding interviews 16 | 17 | Test report is also attached in [resources](online_assessment/resources/Report_TeamApt_Back-End_Developer_Hiring_Test.pdf) in **PDF** format -------------------------------------------------------------------------------- /src/test/java/interviews/glovo/live_coding_interview/questions/Question1Test.java: -------------------------------------------------------------------------------- 1 | package interviews.glovo.live_coding_interview.questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class Question1Test { 7 | @Test 8 | public void success_isAnagram_test_0() { 9 | Assert.assertEquals(Question1.isAnagram("ABCD", "DABC"),true); 10 | } 11 | 12 | @Test 13 | public void success_isAnagram_test_1() { 14 | Assert.assertEquals(Question1.isAnagram("AABB", "BBAA"),true); 15 | } 16 | 17 | @Test 18 | public void failure_isAnagram_test_2() { 19 | Assert.assertEquals(Question1.isAnagram("AAAB", "AABB"),false); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/amazon_questions/interviewbit/MajorityElement.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | import java.util.List; 4 | 5 | public class MajorityElement { 6 | public static int majorityElement(final List A) { 7 | int maj = A.get(0), maj_count = 1; 8 | 9 | for(int i = 1; i < A.size(); i++){ 10 | if(A.get(i) == maj){ 11 | maj_count++; 12 | } 13 | else{ 14 | maj_count--; 15 | if(maj_count == 0){ 16 | maj = A.get(i); 17 | maj_count = 1; 18 | } 19 | } 20 | } 21 | 22 | return maj; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/interviews/avenue_code/Readme.md: -------------------------------------------------------------------------------- 1 | ## Java Engineer | Back-End Developer 2 | Process has only 3 stages in total, two with Avenue Code (technical assessment and behavioral interview) and then the 3 | final interview with our client. 4 | 5 | ## Coding Assessment On Hackerrank 6 | **Time**: 4 hours, **Questions**: Consist of 4 sections, 1st section contains 10 other contains 1 7 | 8 | Please check the [coding_challenge_hackerrank](coding_challenge_hackerrank) folder to check list of questions asked in 9 | previous Coding Assessment 10 | 11 | ## Behavioral Interview 12 | **Time**: 30 min 13 | 14 | ## Final Interview with Client 15 | **Time**: 1-2 hours 16 | 17 | Good luck with the preparation ! 18 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/string_manipulation/SpecialStringAgainTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.string_manipulation; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class SpecialStringAgainTest { 7 | @Test 8 | public void success_substrCount_test_0() { 9 | Assert.assertEquals(SpecialStringAgain.substrCount(5, "asasd"), 7); 10 | } 11 | 12 | @Test 13 | public void success_substrCount_test_1() { 14 | Assert.assertEquals(SpecialStringAgain.substrCount(7, "abcbaba"), 10); 15 | } 16 | 17 | @Test 18 | public void success_substrCount_test_2() { 19 | Assert.assertEquals(SpecialStringAgain.substrCount(4, "aaaa"), 10); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/greedy_algorithms/MinimumAbsoluteDifferenceInAnArray.java: -------------------------------------------------------------------------------- 1 | package hackerrank.greedy_algorithms; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | public class MinimumAbsoluteDifferenceInAnArray { 7 | public static int minimumAbsoluteDifference(List arr) { 8 | Collections.sort(arr); 9 | int difference = Math.abs(arr.get(0) - arr.get(1)); 10 | for (int i = 1 ; i < arr.size(); i++) { 11 | int tempDifference = Math.abs(arr.get(i) - arr.get(i - 1)); 12 | if (tempDifference prices, int k) { 8 | Collections.sort(prices); 9 | Integer sum = 0; 10 | Integer index = 0; 11 | Integer count = 0; 12 | while (sum < k) { 13 | Integer unit = prices.get(index); 14 | if (unit < k && sum + unit <= k) { 15 | sum += unit; 16 | count++; 17 | } else { 18 | break; 19 | } 20 | index++; 21 | } 22 | return count; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/warm_up_challenges/RepeatedStringTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.warm_up_challenges; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class RepeatedStringTest { 7 | @Test 8 | public void success_jumpingOnClouds_example() { 9 | Assert.assertEquals(RepeatedString.repeatedString("abcac", 10), 4); 10 | } 11 | 12 | @Test 13 | public void success_jumpingOnClouds_test_0() { 14 | Assert.assertEquals(RepeatedString.repeatedString("aba", 10), 7); 15 | } 16 | 17 | @Test 18 | public void success_jumpingOnClouds_test_1() { 19 | Assert.assertEquals(RepeatedString.repeatedString("a", 1000000000000l), 1000000000000l); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/greedy_algorithms/GreedyFloristTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.greedy_algorithms; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class GreedyFloristTest { 7 | @Test 8 | public void success_getMinimumCost_test_0() { 9 | Assert.assertEquals(GreedyFlorist.getMinimumCost(3, new int[]{2, 5, 6}), 13); 10 | } 11 | 12 | @Test 13 | public void success_getMinimumCost_test_1() { 14 | Assert.assertEquals(GreedyFlorist.getMinimumCost(2, new int[]{2, 5, 6}), 15); 15 | } 16 | 17 | @Test 18 | public void success_getMinimumCost_test_2() { 19 | Assert.assertEquals(GreedyFlorist.getMinimumCost(3, new int[]{1, 3, 5, 7, 9}), 29); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/string_manipulation/MakingAnagramTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.string_manipulation; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class MakingAnagramTest { 7 | @Test 8 | public void success_makeAnagram_test_0() { 9 | Assert.assertEquals(MakingAnagram.makeAnagram("cde","abc"), 4); 10 | } 11 | 12 | @Test 13 | public void success_makeAnagram_test_1() { 14 | Assert.assertEquals(MakingAnagram.makeAnagram("fcrxzwscanmligyxyvym","jxwtrhvujlmrpdoqbisbwhmgpmeoke"), 30); 15 | } 16 | 17 | @Test 18 | public void success_makeAnagram_test_2() { 19 | Assert.assertEquals(MakingAnagram.makeAnagram("showman","woman"), 2); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/interviews/aurora_solutions/coding_challenge_coderbyte/question/Question2.java: -------------------------------------------------------------------------------- 1 | package interviews.aurora_solutions.coding_challenge_coderbyte.question; 2 | 3 | public class Question2 { 4 | public static String StringChallenge(String str) { 5 | String output = ""; 6 | boolean lastWasOdd = false; 7 | 8 | for (int i = 0; i < str.length(); i++) { 9 | int digit = Character.getNumericValue(str.charAt(i)); 10 | 11 | if (digit % 2 == 1 && lastWasOdd) { 12 | output += "-"; 13 | } 14 | 15 | output += digit; 16 | 17 | lastWasOdd = digit % 2 == 1 && digit != 0; 18 | } 19 | 20 | return output; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/amazon_questions/interviewbit/GasStation.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | import java.util.List; 4 | 5 | public class GasStation { 6 | public static int canCompleteCircuit(final List gas, final List cost) { 7 | int fuel = 0, start_i = 0, sum = 0; 8 | 9 | for(int i = 0; i < gas.size(); i++){ 10 | sum = sum + (gas.get(i) - cost.get(i)); 11 | fuel = fuel + (gas.get(i) - cost.get(i)); 12 | if(fuel < 0){ 13 | fuel = 0; 14 | start_i = i+1; 15 | } 16 | } 17 | 18 | if(sum >= 0){ 19 | return start_i%(gas.size()); 20 | } 21 | 22 | return -1; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/interviews/amazon/coding_challenge_hackerrank/questions/Question3.java: -------------------------------------------------------------------------------- 1 | package interviews.amazon.coding_challenge_hackerrank.questions; 2 | 3 | import java.util.List; 4 | 5 | public class Question3 { 6 | public static Integer countDecreasingRatings(List ratings) { 7 | Integer n = ratings.size(); 8 | if (n == 0) return 0; 9 | Integer i = 0; 10 | Integer result = 1; 11 | for (int j = 1; j < n; j++) { 12 | if ((ratings.get(j - 1) - ratings.get(j)) == 1) { 13 | result += (j - i + 1); 14 | } else { 15 | i = j; 16 | result += 1; 17 | } 18 | 19 | } 20 | return result; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/interviews/amazon/coding_challenge_hackerrank/questions/Question4Test.java: -------------------------------------------------------------------------------- 1 | package interviews.amazon.coding_challenge_hackerrank.questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class Question4Test { 9 | @Test 10 | public void success_countDecreasingRatings_test_0() { 11 | Assert.assertTrue(Question4.findMaximumSustainableClusterSize(Arrays.asList(10,8,7), Arrays.asList(11,12,19), 6).equals(0)); 12 | } 13 | 14 | @Test 15 | public void success_countDecreasingRatings_test_1() { 16 | Assert.assertTrue(Question4.findMaximumSustainableClusterSize(Arrays.asList(4,1,4,5,3), Arrays.asList(8,8,10,9,12), 33).equals(2)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/dsa/mathematics_and_number_theory/Factorial.java: -------------------------------------------------------------------------------- 1 | package dsa.mathematics_and_number_theory; 2 | 3 | 4 | import java.math.BigInteger; 5 | 6 | /** 7 | * Factorial of a number
8 | * Find the factorial of 5, 10 and 1000 9 | */ 10 | public class Factorial { 11 | public static String find(BigInteger n) { 12 | BigInteger result = BigInteger.ONE; 13 | BigInteger index = BigInteger.TWO; 14 | BigInteger limit = n.add(BigInteger.ONE); 15 | while (!index.equals(limit)) { 16 | result = result.multiply(index); 17 | index = index.add(BigInteger.ONE); 18 | } 19 | System.out.println("Result is: " + result); 20 | return String.valueOf(result); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/sorting/MarkAndToysTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.sorting; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class MarkAndToysTest { 9 | @Test 10 | public void success_maximumToys_test_0() { 11 | Assert.assertEquals(MarkAndToys.maximumToys(Arrays.asList(1, 12, 5, 111, 200, 1000, 10), 50), 4); 12 | } 13 | 14 | @Test 15 | public void success_maximumToys_test_1() { 16 | Assert.assertEquals(MarkAndToys.maximumToys(Arrays.asList(1, 2, 3, 4), 7), 3); 17 | } 18 | 19 | @Test 20 | public void success_maximumToys_test_2() { 21 | Assert.assertEquals(MarkAndToys.maximumToys(Arrays.asList(3, 7, 2, 9, 4), 15), 3); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/search/HashTablesIceCreamParlor.java: -------------------------------------------------------------------------------- 1 | package hackerrank.search; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | 6 | public class HashTablesIceCreamParlor { 7 | public static void whatFlavors(List cost, int money) { 8 | HashMap map = new HashMap<>(); 9 | for (int i = 0; i < cost.size(); i++) { 10 | int complement = money - cost.get(i); 11 | if (map.containsKey(complement)) { 12 | System.out.println((map.get(complement) + 1) + " " + (i + 1)); 13 | return; 14 | } 15 | map.put(cost.get(i), i); 16 | } 17 | System.out.println("Error: no two flavors add up to the total cost."); 18 | } 19 | } -------------------------------------------------------------------------------- /src/test/java/hackerrank/greedy_algorithms/MaxMinTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.greedy_algorithms; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class MaxMinTest { 9 | @Test 10 | public void success_getMinimumCost_test_0() { 11 | Assert.assertEquals(MaxMin.maxMin(3, Arrays.asList(10, 100, 300, 200, 1000, 20, 30)), 20); 12 | } 13 | 14 | @Test 15 | public void success_getMinimumCost_test_1() { 16 | Assert.assertEquals(MaxMin.maxMin(4, Arrays.asList(1, 2, 3, 4, 10, 20, 30, 40, 100, 200)), 3); 17 | } 18 | 19 | @Test 20 | public void success_getMinimumCost_test_2() { 21 | Assert.assertEquals(MaxMin.maxMin(2, Arrays.asList(1, 2, 1, 2, 1)), 0); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/leetcode/ClimbingStairsTest.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class ClimbingStairsTest { 7 | @Test 8 | public void success_climbStairs_test_0() { 9 | Assert.assertEquals(ClimbingStairs.climbStairs(2), 2); 10 | } 11 | 12 | @Test 13 | public void success_climbStairs_test_1() { 14 | Assert.assertEquals(ClimbingStairs.climbStairs(3), 3); 15 | } 16 | 17 | @Test 18 | public void success_climbStairs_test_2() { 19 | Assert.assertEquals(ClimbingStairs.climbStairs(5), 8); 20 | } 21 | 22 | @Test 23 | public void success_climbStairs_test_3() { 24 | Assert.assertEquals(ClimbingStairs.climbStairs(45), 1836311903); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/leetcode/ValidParenthesesTest.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class ValidParenthesesTest { 7 | @Test 8 | public void success_isValid_test_0() { 9 | Assert.assertEquals(ValidParentheses.isValid("()"),true); 10 | } 11 | 12 | @Test 13 | public void success_isValid_test_1() { 14 | Assert.assertEquals(ValidParentheses.isValid("()[]{}"),true); 15 | } 16 | 17 | @Test 18 | public void success_isValid_test_2() { 19 | Assert.assertEquals(ValidParentheses.isValid("(]"),false); 20 | } 21 | 22 | @Test 23 | public void success_isValid_test_3() { 24 | Assert.assertEquals(ValidParentheses.isValid("([{}])"),true); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/greedy_algorithms/ReverseShuffleMergeTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.greedy_algorithms; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class ReverseShuffleMergeTest { 7 | @Test 8 | public void success_reverseShuffleMerge_test_0() { 9 | Assert.assertEquals(ReverseShuffleMerge.reverseShuffleMerge("eggegg"), "egg"); 10 | } 11 | 12 | @Test 13 | public void success_reverseShuffleMerge_test_1() { 14 | Assert.assertEquals(ReverseShuffleMerge.reverseShuffleMerge("abcdefgabcdefg"), "agfedcb"); 15 | } 16 | 17 | @Test 18 | public void success_reverseShuffleMerge_test_2() { 19 | Assert.assertEquals(ReverseShuffleMerge.reverseShuffleMerge("aeiouuoiea"), "aeiou"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/string_manipulation/AlternatingCharactersTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.string_manipulation; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class AlternatingCharactersTest { 7 | @Test 8 | public void success_alternatingCharacters_test_0() { 9 | Assert.assertEquals(AlternatingCharacters.alternatingCharacters("AAAA"), 3); 10 | } 11 | 12 | @Test 13 | public void success_alternatingCharacters_test_1() { 14 | Assert.assertEquals(AlternatingCharacters.alternatingCharacters("AAABBBAABB"), 6); 15 | } 16 | 17 | @Test 18 | public void success_alternatingCharacters_test_2() { 19 | Assert.assertEquals(AlternatingCharacters.alternatingCharacters("ABBABBAA"), 3); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/leetcode/LongestCommonPrefix.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | public class LongestCommonPrefix { 4 | public static String find(String[] strs) { 5 | if (strs == null || strs.length == 0) { 6 | return ""; 7 | } 8 | 9 | int n = strs.length; 10 | 11 | if (n == 1) { 12 | return strs[0]; 13 | } 14 | 15 | String result = strs[0]; 16 | for (int i = 1; i < n; i++) { 17 | while (strs[i].indexOf(result) != 0) { 18 | result = result.substring(0, result.length() - 1); 19 | if (result.isEmpty()) 20 | return ""; 21 | } 22 | System.out.println(result); 23 | } 24 | 25 | 26 | return result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/arrays/MinimumSwapsTwoTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.arrays; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class MinimumSwapsTwoTest { 7 | @Test 8 | public void success_minimumSwaps_example() { 9 | int[] arr = new int[]{4,3,1,2}; 10 | Assert.assertEquals(MinimumSwapsTwo.minimumSwaps(arr), 3); 11 | } 12 | 13 | @Test 14 | public void success_minimumSwaps_test_0() { 15 | int[] arr = new int[]{2,3,4,1,5}; 16 | Assert.assertEquals(MinimumSwapsTwo.minimumSwaps(arr), 3); 17 | } 18 | 19 | @Test 20 | public void success_minimumSwaps_test_1() { 21 | int[] arr = new int[]{1,3,5,2,4,6,7}; 22 | Assert.assertEquals(MinimumSwapsTwo.minimumSwaps(arr), 3); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/arrays/NewYearChaosTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.arrays; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | public class NewYearChaosTest { 9 | @Test 10 | public void success_minimumBribes_example() { 11 | List array = Arrays.asList(2,1,5,3,4); 12 | NewYearChaos.minimumBribes(array); 13 | } 14 | 15 | @Test 16 | public void success_minimumBribes_test_0() { 17 | List array = Arrays.asList(2,5,1,3,4); 18 | NewYearChaos.minimumBribes(array); 19 | } 20 | 21 | @Test 22 | public void success_minimumBribes_test_1() { 23 | List array = Arrays.asList(1,2,5,3,7,8,6,4); 24 | NewYearChaos.minimumBribes(array); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/warm_up_challenges/JumpingOnTheCloudsTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.warm_up_challenges; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class JumpingOnTheCloudsTest { 9 | @Test 10 | public void success_jumpingOnClouds_example() { 11 | Assert.assertEquals(JumpingOnTheClouds.jumpingOnClouds(Arrays.asList(0,1,0,0,0,1,0)), 3); 12 | } 13 | 14 | @Test 15 | public void success_jumpingOnClouds_test_0() { 16 | Assert.assertEquals(JumpingOnTheClouds.jumpingOnClouds(Arrays.asList(0,0,1,0,0,1,0)), 4); 17 | } 18 | 19 | @Test 20 | public void success_jumpingOnClouds_test_1() { 21 | Assert.assertEquals(JumpingOnTheClouds.jumpingOnClouds(Arrays.asList(0,0,0,1,0,0)), 3); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/leetcode/SqrtTest.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class SqrtTest { 7 | @Test 8 | public void success_mySqrt_test_0() { 9 | Assert.assertEquals(Sqrt.mySqrt(8), 2); 10 | } 11 | 12 | @Test 13 | public void success_mySqrt_test_1() { 14 | Assert.assertEquals(Sqrt.mySqrt(2147483647), 46340); 15 | } 16 | 17 | @Test 18 | public void success_mySqrt_test_2() { 19 | Assert.assertEquals(Sqrt.mySqrt(81), 9); 20 | } 21 | 22 | @Test 23 | public void success_mySqrt_test_3() { 24 | Assert.assertEquals(Sqrt.mySqrt(4), 2); 25 | } 26 | 27 | @Test 28 | public void success_mySqrt_test_4() { 29 | Assert.assertEquals(Sqrt.mySqrt(3), 1); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/interviews/glovo/live_coding_interview/questions/Question2.java: -------------------------------------------------------------------------------- 1 | package interviews.glovo.live_coding_interview.questions; 2 | 3 | import leetcode.ValidParentheses; 4 | 5 | import java.util.ArrayDeque; 6 | import java.util.Deque; 7 | 8 | //Write an algorithm that given a string containing any combination of the characters 9 | //'(', ')', '{', '}', '[' and ']', determines if the input string is valid. 10 | // 11 | //An input string is valid when: 12 | // 13 | //- Opening parentheses are closed by the same type of closing parentheses, and 14 | //- Opening parentheses are closed in the correct order. 15 | //https://codeshare.io/eVe4LA 16 | public class Question2 { 17 | public static boolean containingAnyCombination(String expr){ 18 | return ValidParentheses.isValid(expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/interviews/callsign/live_coding_interview/questions/Question1.java: -------------------------------------------------------------------------------- 1 | package interviews.callsign.live_coding_interview.questions; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Question1 { 7 | private Map hosts; 8 | 9 | public Question1() { 10 | hosts = new HashMap<>(); 11 | } 12 | 13 | public String allocate(String hostType) { 14 | hosts.put(hostType, hosts.getOrDefault(hostType, 0) + 1); 15 | return hostType + ":" + hosts.get(hostType); 16 | } 17 | 18 | public void deallocate(String hostname) { 19 | String[] parts = hostname.split(":"); 20 | String hostType = parts[0]; 21 | int hostNumber = Integer.parseInt(parts[1]); 22 | hosts.put(hostType, hostNumber - 1); 23 | } 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/dictionaries_and_hashmaps/CountTripletsTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.dictionaries_and_hashmaps; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class CountTripletsTest { 9 | @Test 10 | public void success_countTriplets_example() { 11 | Assert.assertEquals(CountTriplets.countTriplets(Arrays.asList(1l,2l,2l,4l), 2), 2); 12 | } 13 | 14 | @Test 15 | public void success_checkMagazineUsingMap_test_0() { 16 | Assert.assertEquals(CountTriplets.countTriplets(Arrays.asList(1l, 3l, 9l, 9l, 27l, 81l), 3), 6); 17 | } 18 | 19 | @Test 20 | public void success_checkMagazineUsingMap_test_1() { 21 | Assert.assertEquals(CountTriplets.countTriplets(Arrays.asList(1l, 5l, 5l, 25l, 125l), 5), 4); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/arrays/ArraysLeftRotation.java: -------------------------------------------------------------------------------- 1 | package hackerrank.arrays; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | public class ArraysLeftRotation { 7 | /* 8 | * Complete the 'rotLeft' function below. 9 | * 10 | * The function is expected to return an INTEGER_ARRAY. 11 | * The function accepts following parameters: 12 | * 1. INTEGER_ARRAY a 13 | * 2. INTEGER d 14 | */ 15 | public static List rotLeft(List a, int d) { 16 | LinkedList list = new LinkedList<>(a); 17 | for (int i = 0; i < d; i++) { 18 | int first = list.get(0); 19 | list.remove(0); 20 | list.addLast(first); 21 | System.out.println("List is: " + list); 22 | } 23 | return list; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/amazon_questions/SumOfTwoIntegersInArrayEqualsGivenValueTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class SumOfTwoIntegersInArrayEqualsGivenValueTest { 10 | @Test 11 | public void success_findMissingNumberInArray_test_0() { 12 | List arr = Arrays.asList(3, 7, 1, 2, 8, 4, 5); 13 | Assert.assertTrue(SumOfTwoIntegersInArrayEqualsGivenValue.isSumOfTwoIntegersInArrayEqualsGivenValue(arr, 10)); 14 | } 15 | 16 | @Test 17 | public void success_findMissingNumberInArray_test_1() { 18 | List arr = Arrays.asList(3, 7, 1, 2, 8, 4, 5); 19 | Assert.assertFalse(SumOfTwoIntegersInArrayEqualsGivenValue.isSumOfTwoIntegersInArrayEqualsGivenValue(arr, 0)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/interviews/aurora_solutions/coding_challenge_coderbyte/question/Question2Test.java: -------------------------------------------------------------------------------- 1 | package interviews.aurora_solutions.coding_challenge_coderbyte.question; 2 | 3 | import org.junit.Test; 4 | 5 | import static interviews.aurora_solutions.coding_challenge_coderbyte.question.Question2.StringChallenge; 6 | 7 | public class Question2Test { 8 | @Test 9 | public void success_StringChallenge_test_cases() { 10 | String input1 = "99946"; 11 | String expectedOutput1 = "9-9-946"; 12 | String output1 = StringChallenge(input1); 13 | assert output1.equals(expectedOutput1) : "Test Case 1 Failed"; 14 | 15 | String input2 = "56730"; 16 | String expectedOutput2 = "567-30"; 17 | String output2 = StringChallenge(input2); 18 | assert output2.equals(expectedOutput2) : "Test Case 2 Failed"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/amazon_questions/PythagoreanTripletTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class PythagoreanTripletTest { 10 | @Test 11 | public void success_isTriplet_test_0() { 12 | List arr = Arrays.asList(3, 1, 4, 6, 5); 13 | Assert.assertTrue(PythagoreanTriplet.isTriplet(arr)); 14 | } 15 | 16 | @Test 17 | public void success_isTriplet_test_1() { 18 | List arr = Arrays.asList(10, 4, 6, 12, 5); 19 | Assert.assertFalse(PythagoreanTriplet.isTriplet(arr)); 20 | } 21 | 22 | @Test 23 | public void success_isTriplet_test_2() { 24 | List arr = Arrays.asList(3, 4, 6, 5); 25 | Assert.assertTrue(PythagoreanTriplet.isTriplet(arr)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/dictionaries_and_hashmaps/TwoStringsTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.dictionaries_and_hashmaps; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class TwoStringsTest { 7 | @Test 8 | public void success_twoStrings_example_0() { 9 | Assert.assertEquals(TwoStrings.twoStrings("and","art"), "YES"); 10 | } 11 | 12 | @Test 13 | public void success_twoStrings_example_1() { 14 | Assert.assertEquals(TwoStrings.twoStrings("be","cat"), "NO"); 15 | } 16 | 17 | @Test 18 | public void success_twoStrings_test_0() { 19 | Assert.assertEquals(TwoStrings.twoStrings("wouldyoulikefries","abcabcabcabcabcabc"), "NO"); 20 | } 21 | 22 | @Test 23 | public void success_twoStrings_test_1() { 24 | Assert.assertEquals(TwoStrings.twoStrings("aardvark","apple"), "YES"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/interviews/callsign/live_coding_interview/Readme.md: -------------------------------------------------------------------------------- 1 | ### Question 1 2 | Host Tracker: Server names consist of an alphabetic host type (e.g. "apibox") 3 | concatenated with the server number, with server numbers allocated as before 4 | (so, "apibox:1", "apibox:2", etc. are valid hostnames). Write a name tracking class with two operations, 5 | allocate(host_type) and deallocate(hostname). The former should reserve and return the next available hostname, 6 | while the latter should release that hostname back into the pool. 7 | 8 | **Examples:** 9 | ``` 10 | Input: 11 | allocate("apibox") 12 | Output: 13 | "apibox:1" 14 | 15 | Input: 16 | allocate("apibox") 17 | Output: 18 | "apibox:2" 19 | 20 | Input: 21 | deallocate("apibox") 22 | 23 | Input: 24 | allocate("apibox") 25 | Output: 26 | "apibox:1" 27 | 28 | Input: 29 | allocate("sitebox") 30 | Output: 31 | "sitebox:1" 32 | ``` -------------------------------------------------------------------------------- /src/test/java/hackerrank/sorting/FraudulentActivityNotificationsTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.sorting; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class FraudulentActivityNotificationsTest { 9 | @Test 10 | public void success_activityNotifications_test_0() { 11 | Assert.assertEquals(FraudulentActivityNotifications.activityNotifications(Arrays.asList(2,3,4,2,3,6,8,4,5), 5), 2); 12 | } 13 | 14 | @Test 15 | public void success_activityNotifications_test_1() { 16 | Assert.assertEquals(FraudulentActivityNotifications.activityNotifications(Arrays.asList(1,2,3,4,4), 4), 0); 17 | } 18 | 19 | @Test 20 | public void success_activityNotifications_test_2() { 21 | Assert.assertEquals(FraudulentActivityNotifications.activityNotifications(Arrays.asList(10,20,30,40,50), 3), 1); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/coding_challenge_hackerrank/question/Question2.java: -------------------------------------------------------------------------------- 1 | package interviews.remotebase.coding_challenge_hackerrank.question; 2 | 3 | public class Question2 { 4 | public static int countTeams(int[] skills, int minplayers, int minLevel, int maxLevel) { 5 | int count = 0; 6 | for (int skill : skills) { 7 | if (minLevel <= skill && skill <= maxLevel) { 8 | count++; 9 | } 10 | } 11 | int result = 0; 12 | for (int i = minplayers; i <= count; i++) { 13 | int combination = 1; 14 | for (int j = count; j > count - i; j--) { 15 | combination *= j; 16 | } 17 | for (int j = i; j > 1; j--) { 18 | combination /= j; 19 | } 20 | result += combination; 21 | } 22 | return result; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/dsa/bit_manipulation/NonRepeatingElementInArrayElementsRepeatingKthTimeTest.java: -------------------------------------------------------------------------------- 1 | package dsa.bit_manipulation; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class NonRepeatingElementInArrayElementsRepeatingKthTimeTest { 9 | @Test 10 | public void success_find_test_0() { 11 | Assert.assertTrue(NonRepeatingElementInArrayElementsRepeatingKthTime.find(Arrays.asList(2,2,1,5,1,1,2), 3).equals(5)); 12 | } 13 | 14 | @Test 15 | public void success_find_test_1() { 16 | Assert.assertTrue(NonRepeatingElementInArrayElementsRepeatingKthTime.find(Arrays.asList(5,5,5,10),3).equals(10)); 17 | } 18 | 19 | @Test 20 | public void success_find_test_2() { 21 | Assert.assertTrue(NonRepeatingElementInArrayElementsRepeatingKthTime.find(Arrays.asList(5,5,5,5,10,2,10,10,10),4).equals(2)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contribution Guidelines 2 | 3 | ### Docs 4 | Add concepts being asked in interviews in pdf or md format and make sure that concept detail is 100% authentic and useful, do not add material which will cause time loss. 5 | please make sure you have added the relevant file in docs folder then create a merge request. 6 | 7 | ### Coding Practice(Hackerrank, InterviewBit, LeetCode) 8 | Solve Problems using Java and create a pull request. We expect you to write test cases for every problem you have solved 9 | and make sure to add at least 4 or 5 test cases as without that we will not proceed further. 10 | 11 | ### Interviews 12 | Solve Problems using Java and create a pull request. Please follow the same package standard which we follow on **Glovo**, 13 | and we expect you to write test cases for every problem you have solved 14 | and make sure to add at least 4 or 5 test cases as without that we will not proceed further. 15 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/dictionaries_and_hashmaps/SherLockAndAnagramsTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.dictionaries_and_hashmaps; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class SherLockAndAnagramsTest { 7 | @Test 8 | public void success_sherlockAndAnagrams_example_0() { 9 | Assert.assertEquals(SherLockAndAnagrams.sherlockAndAnagrams("mom"), 2); 10 | } 11 | 12 | @Test 13 | public void success_sherlockAndAnagrams_test_0() { 14 | Assert.assertEquals(SherLockAndAnagrams.sherlockAndAnagrams("abba"), 4); 15 | } 16 | 17 | @Test 18 | public void success_sherlockAndAnagrams_test_1() { 19 | Assert.assertEquals(SherLockAndAnagrams.sherlockAndAnagrams("abcd"), 0); 20 | } 21 | 22 | @Test 23 | public void success_sherlockAndAnagrams_test_2() { 24 | Assert.assertEquals(SherLockAndAnagrams.sherlockAndAnagrams("kkkk"), 10); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/interviews/aurora_solutions/coding_challenge_coderbyte/question/Question3Test.java: -------------------------------------------------------------------------------- 1 | package interviews.aurora_solutions.coding_challenge_coderbyte.question; 2 | 3 | import org.junit.Test; 4 | 5 | import static interviews.aurora_solutions.coding_challenge_coderbyte.question.Question3.ArrayChallenge; 6 | 7 | public class Question3Test { 8 | @Test 9 | public void success_ArrayChallenge_test_cases() { 10 | int[] input1 = {5, 3, 1, 9, 7, 3, 4, 1}; 11 | String expectedOutput1 = "-1 -1 -1 1 1 1 3 1"; 12 | String actualOutput1 = ArrayChallenge(input1); 13 | assert actualOutput1.equals(expectedOutput1) : "Test Case 1 Failed"; 14 | 15 | int[] input2 = {2, 4, 5, 1, 7}; 16 | String expectedOutput2 = "-1 2 4 -1 1"; 17 | String actualOutput2 = ArrayChallenge(input2); 18 | assert actualOutput2.equals(expectedOutput2) : "Test Case 2 Failed"; 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/interviews/remotebase/coding_challenge_hackerrank/questions/Question3Test.java: -------------------------------------------------------------------------------- 1 | package interviews.remotebase.coding_challenge_hackerrank.questions; 2 | 3 | import interviews.remotebase.coding_challenge_hackerrank.question.Question3; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class Question3Test { 8 | @Test 9 | public void success_getString_example_0() { 10 | Assert.assertEquals(Question3.getString("bbcacad"), "aabcbcd"); 11 | } 12 | 13 | @Test 14 | public void success_getString_test_0() { 15 | Assert.assertEquals(Question3.getString("bdea"), "abde"); 16 | } 17 | @Test 18 | public void success_getString_test_1() { 19 | Assert.assertEquals(Question3.getString("abbbe"), "abbbe"); 20 | } 21 | @Test 22 | public void success_getString_test_2() { 23 | Assert.assertEquals(Question3.getString("tsraa"), "arstt"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/sorting/BubbleSort.java: -------------------------------------------------------------------------------- 1 | package hackerrank.sorting; 2 | 3 | import java.util.List; 4 | 5 | public class BubbleSort { 6 | public static void countSwaps(List a) { 7 | Integer swapCount = 0; 8 | Integer n = a.size(); 9 | for (int i = 0; i < n; i++) { 10 | for (int j = 0; j < n - 1; j++) { 11 | Integer swap1 = a.get(j); 12 | Integer swap2 = a.get(j + 1); 13 | if (swap1 > swap2) { 14 | a.set(j, swap2); 15 | a.set(j + 1, swap1); 16 | swapCount++; 17 | } 18 | } 19 | } 20 | System.out.println(String.format("Array is sorted in %d swaps.", swapCount)); 21 | System.out.println(String.format("First Element: %d", a.get(0))); 22 | System.out.println(String.format("Last Element: %d", a.get(n - 1))); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/interviews/glovo/live_coding_interview/questions/Question2Test.java: -------------------------------------------------------------------------------- 1 | package interviews.glovo.live_coding_interview.questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class Question2Test { 7 | @Test 8 | public void success_containingAnyCombination_test_0() { 9 | Assert.assertEquals(Question2.containingAnyCombination("()"),true); 10 | } 11 | 12 | @Test 13 | public void success_containingAnyCombination_test_1() { 14 | Assert.assertEquals(Question2.containingAnyCombination("()[]{}"),true); 15 | } 16 | 17 | @Test 18 | public void success_containingAnyCombination_test_2() { 19 | Assert.assertEquals(Question2.containingAnyCombination("(]"),false); 20 | } 21 | 22 | @Test 23 | public void success_containingAnyCombination_test_3() { 24 | Assert.assertEquals(Question2.containingAnyCombination("([{}])"),true); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/sorting/ComparatorTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.sorting; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | import java.util.Collections; 8 | import java.util.List; 9 | 10 | public class ComparatorTest { 11 | @Test 12 | public void success_compare_test_0() { 13 | List players = Arrays.asList( 14 | new Player("smith", 20), 15 | new Player("jones", 15), 16 | new Player("jones", 20) 17 | ); 18 | List playersSorted = Arrays.asList( 19 | new Player("jones", 20), 20 | new Player("smith", 20), 21 | new Player("jones", 15) 22 | ); 23 | 24 | Comparator comparator = new Comparator(); 25 | Collections.sort(players, comparator); 26 | Assert.assertEquals(players.get(0).name, playersSorted.get(0).name); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/interviews/aurora_solutions/coding_challenge_coderbyte/question/Question1Test.java: -------------------------------------------------------------------------------- 1 | package interviews.aurora_solutions.coding_challenge_coderbyte.question; 2 | 3 | import org.junit.Test; 4 | 5 | import static interviews.aurora_solutions.coding_challenge_coderbyte.question.Question1.StringChallenge; 6 | 7 | public class Question1Test { 8 | @Test 9 | public void success_StringChallenge_test_cases() { 10 | // Test case 1 11 | String input1 = "2a3b5 w1o2rl3d g1gg92"; 12 | String expectedOutput1 = "true"; 13 | String output1 = StringChallenge(input1); 14 | assert output1.equals(expectedOutput1) : "Test Case 1 Failed"; 15 | 16 | // Test case 2 17 | String input2 = "21aa3a ggg4g4g6ggg"; 18 | String expectedOutput2 = "false"; 19 | String output2 = StringChallenge(input2); 20 | assert output2.equals(expectedOutput2) : "Test Case 2 Failed"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/dsa/bit_manipulation/TwoNonRepeatingElementInArray.java: -------------------------------------------------------------------------------- 1 | package dsa.bit_manipulation; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Two non repeating element in array
7 | * Find the two non repeating element in array, where every element repeat twice 8 | */ 9 | public class TwoNonRepeatingElementInArray { 10 | public static String find(List list) { 11 | Integer result = list.get(0) ^ list.get(1); 12 | for (int i = 2; i < list.size(); i++) { 13 | result ^= list.get(i); 14 | } 15 | 16 | Integer evenResult = result; 17 | Integer oddResult = result; 18 | for (int i = 0; i < list.size(); i++) { 19 | if ((list.get(i) & 1) == 0) { 20 | oddResult ^= list.get(i); 21 | } else { 22 | evenResult ^= list.get(i); 23 | } 24 | } 25 | return oddResult + " " + evenResult; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/interviews/aurora_solutions/coding_challenge_coderbyte/question/Question4Test.java: -------------------------------------------------------------------------------- 1 | package interviews.aurora_solutions.coding_challenge_coderbyte.question; 2 | 3 | import org.junit.Test; 4 | 5 | import static interviews.aurora_solutions.coding_challenge_coderbyte.question.Question4.ArrayChallenge; 6 | 7 | public class Question4Test { 8 | @Test 9 | public void success_ArrayChallenge_test_cases() { 10 | // Test case 1 11 | int[] input1 = {5, 7, 16, 1, 2}; 12 | String expectedOutput1 = "false"; 13 | String actualOutput1 = ArrayChallenge(input1); 14 | assert actualOutput1.equals(expectedOutput1) : "Test Case 1 Failed"; 15 | 16 | // Test case 2 17 | int[] input2 = {3, 5, -1, 8, 12}; 18 | String expectedOutput2 = "true"; 19 | String actualOutput2 = ArrayChallenge(input2); 20 | assert actualOutput2.equals(expectedOutput2) : "Test Case 2 Failed"; 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/greedy_algorithms/LuckBalance.java: -------------------------------------------------------------------------------- 1 | package hackerrank.greedy_algorithms; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class LuckBalance { 8 | public static int luckBalance(int k, List> contests) { 9 | int luck = 0; 10 | List importantContests = new ArrayList<>(); 11 | for (int i = 0; i < contests.size(); i++) { 12 | luck += contests.get(i).get(0); 13 | if(contests.get(i).get(1) == 1){ 14 | importantContests.add(contests.get(i).get(0)); 15 | } 16 | } 17 | if (importantContests.size() == k){ 18 | return luck; 19 | } 20 | Collections.sort(importantContests); 21 | for (int i = 0; i < importantContests.size() - k; i++) { 22 | luck -= 2 * importantContests.get(i); 23 | } 24 | return luck; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/interviews/avenue_code/coding_challenge_hackerrank/questions/Section2Question2Test.java: -------------------------------------------------------------------------------- 1 | package interviews.avenue_code.coding_challenge_hackerrank.questions; 2 | 3 | import org.junit.Test; 4 | 5 | import static interviews.avenue_code.coding_challenge_hackerrank.questions.Section2Question2.bestInGenre; 6 | 7 | public class Section2Question2Test { 8 | @Test 9 | public void success_StringChallenge_test_cases() { 10 | // Test case 1 11 | // String input1 = "Action"; 12 | // String expectedOutput1 = "Game of Thrones"; 13 | // String output1 = bestInGenre(input1); 14 | // assert output1.equals(expectedOutput1) : "Test Case 1 Failed"; 15 | 16 | // Test case 2 17 | String input2 = "Animation"; 18 | String expectedOutput2 = "Avatar: The Last Airbender"; 19 | String output2 = bestInGenre(input2); 20 | assert output2.equals(expectedOutput2) : "Test Case 2 Failed"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/leetcode/PlusOneTest.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class PlusOneTest { 7 | @Test 8 | public void success_plusOne_test_0() { 9 | int[] result = PlusOne.plusOne(new int[]{1, 2, 3, 4}); 10 | Assert.assertEquals(result[result.length - 1], 5); 11 | } 12 | 13 | @Test 14 | public void success_plusOne_test_1() { 15 | int[] result = PlusOne.plusOne(new int[]{1, 2, 9, 9}); 16 | Assert.assertEquals(result[result.length - 2], 0); 17 | } 18 | 19 | @Test 20 | public void success_plusOne_test_2() { 21 | int[] result = PlusOne.plusOne(new int[]{2, 9, 9}); 22 | Assert.assertEquals(result[result.length - 3], 3); 23 | } 24 | 25 | @Test 26 | public void success_plusOne_test_3() { 27 | int[] result = PlusOne.plusOne(new int[]{9, 9, 9}); 28 | Assert.assertEquals(result[result.length - 4], 1); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/dsa/mathematics_and_number_theory/SieveOfEratoSthenesTest.java: -------------------------------------------------------------------------------- 1 | package dsa.mathematics_and_number_theory; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | public class SieveOfEratoSthenesTest { 8 | private static int size = 100; 9 | private static boolean isPrime[] = new boolean[size]; 10 | 11 | @Before 12 | public void setUp() { 13 | if (isPrime[3] == true) { 14 | return; 15 | } 16 | // do the setup 17 | isPrime = SieveOfEratoSthenes.find(size); 18 | for (int i = 0; i <= size; i++) { 19 | if (isPrime[i]){ 20 | System.out.print(i + ","); 21 | } 22 | } 23 | } 24 | 25 | @Test 26 | public void success_find_test_0() { 27 | Assert.assertTrue(isPrime[7]); 28 | } 29 | 30 | @Test 31 | public void success_find_test_1() { 32 | Assert.assertTrue(isPrime[11]); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/interviews/aurora_solutions/coding_challenge_coderbyte/question/Question3.java: -------------------------------------------------------------------------------- 1 | package interviews.aurora_solutions.coding_challenge_coderbyte.question; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Stack; 6 | import java.util.stream.Collectors; 7 | 8 | public class Question3 { 9 | public static String ArrayChallenge(int[] arr) { 10 | List result = new ArrayList<>(); 11 | Stack stack = new Stack<>(); 12 | 13 | for (int i = 0; i < arr.length; i++) { 14 | while (!stack.empty() && stack.peek() > arr[i]) { 15 | stack.pop(); 16 | } 17 | 18 | if (!stack.empty()) { 19 | result.add(stack.peek()); 20 | } else { 21 | result.add(-1); 22 | } 23 | 24 | stack.push(arr[i]); 25 | } 26 | 27 | return result.stream().map(String::valueOf).collect(Collectors.joining(" ")); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/amazon_questions/MissingNumberInArrayTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class MissingNumberInArrayTest { 10 | @Test 11 | public void success_findMissingNumberInArray_test_0() { 12 | List arr = Arrays.asList(3, 7, 1, 2, 8, 4, 5); 13 | Assert.assertTrue(MissingNumberInArray.findMissingNumberInArray(arr) == 6); 14 | } 15 | 16 | @Test 17 | public void success_findMissingNumberInArray_test_1() { 18 | List arr = Arrays.asList(1,2,3,4,5,6,7,8); 19 | Assert.assertTrue(MissingNumberInArray.findMissingNumberInArray(arr) == -1); 20 | } 21 | 22 | @Test 23 | public void success_findMissingNumberInArray_test_2() { 24 | List arr = Arrays.asList(9, 6, 4, 2, 3, 5, 7, 1); 25 | Assert.assertTrue(MissingNumberInArray.findMissingNumberInArray(arr) == 8); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/amazon_questions/interviewbit/LongestIncreasingSubsequence.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class LongestIncreasingSubsequence { 7 | public static int lis(List arr) 8 | { 9 | int i, j, max = 0, n = arr.size(); 10 | List lis = new ArrayList<>(); 11 | 12 | /* Initialize LIS values for all indexes */ 13 | for (i = 0; i < n; i++) 14 | lis.add(1); 15 | 16 | /* Compute optimized LIS values in bottom up manner */ 17 | for (i = 1; i < n; i++) 18 | for (j = 0; j < i; j++) 19 | if (arr.get(i) > arr.get(j) && lis.get(i) < lis.get(j) + 1) 20 | lis.set(i, lis.get(j) + 1); 21 | 22 | /* Pick maximum of all LIS values */ 23 | for (i = 0; i < n; i++) 24 | if (max < lis.get(i)) 25 | max = lis.get(i); 26 | 27 | return max; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/warm_up_challenges/CountingValleys.md: -------------------------------------------------------------------------------- 1 | An avid hiker keeps meticulous records of their hikes. During the last hike that took exactly steps, for every step it was noted if it was an uphill, **U**, or a downhill, **D** step. Hikes always start and end at sea level, and each step up or down represents a **1** unit change in altitude. We define the following terms: 2 | - A mountain is a sequence of consecutive steps above sea level, starting with a step up from sea level and ending with a step down to sea level. 3 | - A valley is a sequence of consecutive steps below sea level, starting with a step down from sea level and ending with a step up to sea level. 4 | 5 | Given the sequence of up and down steps during a hike, find and print the number of valleys walked through. 6 | 7 | **Example** 8 | 9 | steps = 8 path = [DDUUUUDD] 10 | 11 | 12 | The hiker first enters a valley **2** units deep. Then they climb out and up onto a mountain **2** units high. Finally, the hiker returns to sea level and ends the hike. -------------------------------------------------------------------------------- /src/main/java/interviews/aurora_solutions/coding_challenge_coderbyte/question/Question4.java: -------------------------------------------------------------------------------- 1 | package interviews.aurora_solutions.coding_challenge_coderbyte.question; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | public class Question4 { 8 | public static String ArrayChallenge(int[] arr) { 9 | int max = Arrays.stream(arr).max().getAsInt(); 10 | int sum = Arrays.stream(arr).sum() - max; 11 | 12 | if (sum < max) { 13 | return "false"; 14 | } 15 | 16 | Map memo = new HashMap<>(); 17 | memo.put(0, true); 18 | 19 | for (int i = 0; i < arr.length - 1; i++) { 20 | int curr = arr[i]; 21 | for (int j = max - curr; j >= 0; j--) { 22 | if (memo.containsKey(j)) { 23 | memo.put(j + curr, true); 24 | } 25 | } 26 | } 27 | 28 | return memo.getOrDefault(max, false) ? "true" : "false"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/amazon_questions/MergeTwoSortedLinkedListTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class MergeTwoSortedLinkedListTest { 10 | @Test 11 | public void success_findMissingNumberInArray_test_0() { 12 | List list1 = Arrays.asList(1,2,6,8); 13 | List list2 = Arrays.asList(1,3,4,6,9); 14 | List result = Arrays.asList(1,1,2,3,4,6,6,8,9); 15 | Assert.assertTrue(MergeTwoSortedLinkedList.mergeTwoSortedLinkedList(list1,list2).equals(result)); 16 | } 17 | 18 | @Test 19 | public void success_findMissingNumberInArray_test_1() { 20 | List list1 = Arrays.asList(1,2,6); 21 | List list2 = Arrays.asList(3,4); 22 | List result = Arrays.asList(1,2,3,4,6); 23 | Assert.assertTrue(MergeTwoSortedLinkedList.mergeTwoSortedLinkedList(list1,list2).equals(result)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/amazon_questions/KLargestOrSmallestElementsTest.java: -------------------------------------------------------------------------------- 1 | package amazon_questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class KLargestOrSmallestElementsTest { 10 | @Test 11 | public void success_kSmallestOrLargest_test_0() { 12 | List list = Arrays.asList(3, 7, 1, 2, 8, 4, 5); 13 | List result = Arrays.asList(1, 2, 3); 14 | Assert.assertTrue(KLargestOrSmallestElements.kSmallestOrLargest(list, 3, KLargestOrSmallestElements.KLargestOrSmallestElementsEnum.SMALLEST).equals(result)); 15 | } 16 | 17 | @Test 18 | public void success_kSmallestOrLargest_test_1() { 19 | List list = Arrays.asList(3, 7, 1, 2, 8, 4, 5); 20 | List result = Arrays.asList(5,7,8); 21 | Assert.assertTrue(KLargestOrSmallestElements.kSmallestOrLargest(list, 3, KLargestOrSmallestElements.KLargestOrSmallestElementsEnum.LARGEST).equals(result)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/sorting/MergeSortCountingInversionsTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.sorting; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class MergeSortCountingInversionsTest { 9 | @Test 10 | public void success_countInversions_test_0() { 11 | Assert.assertEquals(MergeSortCountingInversions.countInversions(Arrays.asList(1,1,1,2,2)), 0); 12 | } 13 | 14 | @Test 15 | public void success_countInversions_test_1() { 16 | Assert.assertEquals(MergeSortCountingInversions.countInversions(Arrays.asList(2,1,3,1,2)), 4); 17 | } 18 | 19 | @Test 20 | public void success_countInversionsOptimized_test_0() { 21 | Assert.assertEquals(MergeSortCountingInversions.countInversionsOptimized(Arrays.asList(1,1,1,2,2)), 0); 22 | } 23 | 24 | @Test 25 | public void success_countInversionsOptimized_test_1() { 26 | Assert.assertEquals(MergeSortCountingInversions.countInversionsOptimized(Arrays.asList(2,1,3,1,2)), 4); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/string_manipulation/MakingAnagram.java: -------------------------------------------------------------------------------- 1 | package hackerrank.string_manipulation; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class MakingAnagram { 7 | public static int makeAnagram(String a, String b) { 8 | Integer count = 0; 9 | Map aMap = new HashMap<>(); 10 | for (char s : a.toCharArray()) { 11 | aMap.put(String.valueOf(s), aMap.getOrDefault(String.valueOf(s), 0) + 1); 12 | } 13 | for (char s : b.toCharArray()) { 14 | if (aMap.containsKey(String.valueOf(s))) { 15 | aMap.put(String.valueOf(s), aMap.get(String.valueOf(s)) - 1); 16 | } else { 17 | count++; 18 | } 19 | } 20 | for (Map.Entry entry : aMap.entrySet()) { 21 | Integer value = entry.getValue(); 22 | if (value < 0) { 23 | value *= -1; 24 | } 25 | count += value; 26 | } 27 | return count; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/warm_up_challenges/RepeatedString.java: -------------------------------------------------------------------------------- 1 | package hackerrank.warm_up_challenges; 2 | 3 | public class RepeatedString { 4 | /* 5 | * Complete the 'repeatedString' function below. 6 | * 7 | * The function is expected to return a LONG_INTEGER. 8 | * The function accepts following parameters: 9 | * 1. STRING s 10 | * 2. LONG_INTEGER n 11 | */ 12 | 13 | public static long repeatedString(String s, long n) { 14 | System.out.println("String is: " + s); 15 | long count = 0; 16 | for(int i=0;i ar) 14 | { 15 | HashSet socks = new HashSet<>(); 16 | int count=0; 17 | for(int i=0; i arr, long r) { 9 | long count = 0; 10 | Map after = new HashMap<>(); 11 | for (int i = 0; i < arr.size(); i++) { 12 | Long value = arr.get(i); 13 | after.put(value, after.getOrDefault(value, 0l) + 1); 14 | } 15 | Map before = new HashMap<>(); 16 | for (int i = 0; i < arr.size(); i++) { 17 | Long value = arr.get(i); 18 | after.put(value, after.get(value) - 1); 19 | if (value % r == 0 && before.containsKey(value / r) && after.containsKey(value * r)) { 20 | count += before.get(value / r) * after.get(value * r); 21 | } 22 | before.put(value, before.getOrDefault(value, 0l) + 1); 23 | } 24 | return count; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/interviews/amazon/coding_challenge_hackerrank/questions/Question2.java: -------------------------------------------------------------------------------- 1 | package interviews.amazon.coding_challenge_hackerrank.questions; 2 | 3 | public class Question2 { 4 | public static int findMaxProducts(int[] products) { 5 | int answer = products[0]; 6 | int n = products.length; 7 | 8 | for (int i = 1; i < n; i++) { 9 | int l = products[i]; 10 | int p = products[i]; 11 | int a = products[i]; 12 | for (int j = i - 1; j >= 0; j--) { 13 | if (products[j] >= p) { 14 | l += (a - 1); 15 | a = a - 1; 16 | } else { 17 | if (products[j] < (a - 1)) { 18 | l += products[j]; 19 | a = products[j]; 20 | } else { 21 | l += (a - 1); 22 | a = a - 1; 23 | } 24 | } 25 | } 26 | answer = Math.max(l, answer); 27 | } 28 | return answer; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/arrays/NewYearChaos.java: -------------------------------------------------------------------------------- 1 | package hackerrank.arrays; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | public class NewYearChaos { 7 | /* 8 | * Complete the 'minimumBribes' function below. 9 | * 10 | * The function accepts INTEGER_ARRAY q as parameter. 11 | */ 12 | 13 | public static void minimumBribes(List q) { 14 | int minimumBribes = 0; 15 | Integer index = q.size() - 1; 16 | while (index >= 0) { 17 | int chaosPosition = q.get(index) - (index + 1); 18 | if (chaosPosition > 2) { 19 | System.out.println("Too chaotic"); 20 | return; 21 | } else { 22 | int optimize = Math.max(0,q.get(index)-2); 23 | for (int i=index;i>=optimize;i--) { 24 | if (q.get(index) < q.get(i)) { 25 | minimumBribes++; 26 | } 27 | } 28 | } 29 | index--; 30 | } 31 | System.out.println(minimumBribes); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/interviews/teamapt/online_assessment/questions/Question1Test.java: -------------------------------------------------------------------------------- 1 | package interviews.teamapt.online_assessment.questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class Question1Test { 7 | /** 8 | * Explanation
9 | *
  • The sum of the first two elements, 1+2=3. The value of the last element is 3.
  • 10 | *
  • Using zero based indexing, arr[2]=3 is the pivot between the two subarrays.
  • 11 | *
  • The index of the pivot is 2.
  • 12 | */ 13 | @Test 14 | public void success_balancedSum_test_0() { 15 | Assert.assertEquals(Question1.balancedSum(new int[]{1,2,3,3}),2); 16 | } 17 | 18 | /** 19 | * Explanation
    20 | *
  • The first and last elements are equal to 1.
  • 21 | *
  • Using zero based indexing, arr[1]=2 is the pivot between the two subarrays.
  • 22 | *
  • The index of the pivot is 1.
  • 23 | */ 24 | @Test 25 | public void success_balancedSum_test_1() { 26 | Assert.assertEquals(Question1.balancedSum(new int[]{1,2,1}),1); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/string_manipulation/CommonChild.java: -------------------------------------------------------------------------------- 1 | package hackerrank.string_manipulation; 2 | 3 | public class CommonChild { 4 | public static int commonChild(String s1, String s2) { 5 | int M = s1.length(); 6 | int N = s2.length(); 7 | 8 | int[][] arr = new int[M+1][N+1]; 9 | for (int i = M-1; i >= 0; i--) { 10 | for (int j = N-1; j >= 0; j--) { 11 | if (s1.charAt(i) == s2.charAt(j)) { 12 | arr[i][j] = arr[i + 1][j + 1] + 1; 13 | } else { 14 | arr[i][j] = Math.max(arr[i + 1][j], arr[i][j + 1]); 15 | } 16 | } 17 | } 18 | int i = 0, j = 0; 19 | int count =0; 20 | while(i < M && j < N) { 21 | if (s1.charAt(i) == s2.charAt(j)) { 22 | count++; 23 | i++; 24 | j++; 25 | } 26 | else if (arr[i+1][j] >= arr[i][j+1]) { 27 | i++; 28 | } else { 29 | j++; 30 | } 31 | } 32 | return count; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/amazon_questions/interviewbit/MinimumSumPathInMatrix.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | public class MinimumSumPathInMatrix { 4 | public static int find(int[][] grid) { 5 | if(grid == null || grid.length==0) 6 | return 0; 7 | 8 | int m = grid.length; 9 | int n = grid[0].length; 10 | 11 | int[][] dp = new int[m][n]; 12 | dp[0][0] = grid[0][0]; 13 | 14 | // initialize top row 15 | for(int i=1; i dp[i][j-1]){ 28 | dp[i][j] = dp[i][j-1] + grid[i][j]; 29 | }else{ 30 | dp[i][j] = dp[i-1][j] + grid[i][j]; 31 | } 32 | } 33 | } 34 | 35 | return dp[m-1][n-1]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/string_manipulation/SpecialStringAgain.java: -------------------------------------------------------------------------------- 1 | package hackerrank.string_manipulation; 2 | 3 | public class SpecialStringAgain { 4 | // Complete the substrCount function below. 5 | public static long substrCount(int n, String str) { 6 | for (int i = 0; i < str.length(); i++) { 7 | char iIndexChar = str.charAt(i); 8 | 9 | int middleIndexChar = -1; 10 | 11 | for (int j = i+1; j < str.length(); j++) { 12 | char jIndexChar = str.charAt(j); 13 | 14 | // Check for characters except the middle one are the same and 15 | // All of the characters are the same 16 | if (iIndexChar == jIndexChar) { 17 | if ( (middleIndexChar == -1) || (j - middleIndexChar) == (middleIndexChar - i)) { 18 | n++; 19 | } 20 | } else if (middleIndexChar == -1) { 21 | middleIndexChar = j; 22 | } else { 23 | break; 24 | } 25 | } 26 | } 27 | return n; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/greedy_algorithms/MinimumAbsoluteDifferenceInAnArrayTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.greedy_algorithms; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | public class MinimumAbsoluteDifferenceInAnArrayTest { 9 | @Test 10 | public void success_minimumAbsoluteDifference_test_0() { 11 | Assert.assertEquals(MinimumAbsoluteDifferenceInAnArray.minimumAbsoluteDifference(Arrays.asList(3, -7, 0)), 3); 12 | } 13 | 14 | @Test 15 | public void success_minimumAbsoluteDifference_test_1() { 16 | Assert.assertEquals( 17 | MinimumAbsoluteDifferenceInAnArray.minimumAbsoluteDifference( 18 | Arrays.asList(-59, -36, -13, 1, -53, -92, -2, -96, -54, 75) 19 | ), 1 20 | ); 21 | } 22 | 23 | @Test 24 | public void success_minimumAbsoluteDifference_test_2() { 25 | Assert.assertEquals( 26 | MinimumAbsoluteDifferenceInAnArray.minimumAbsoluteDifference( 27 | Arrays.asList(1, -3, 71, 68, 17) 28 | ), 3 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/warm_up_challenges/JumpingOnTheClouds.java: -------------------------------------------------------------------------------- 1 | package hackerrank.warm_up_challenges; 2 | 3 | import java.util.List; 4 | 5 | public class JumpingOnTheClouds { 6 | /* 7 | * Complete the 'jumpingOnClouds' function below. 8 | * 9 | * The function is expected to return an INTEGER. 10 | * The function accepts INTEGER_ARRAY c as parameter. 11 | */ 12 | 13 | public static int jumpingOnClouds(List c) { 14 | System.out.println("List is: " + c.toString()); 15 | int jumps = 0; 16 | int index = 0; 17 | while (index>=0 && index()); 22 | } 23 | 24 | @Test 25 | public void success_merge_test_2() { 26 | BinaryTreeInorderTraversal.TreeNode treeNode = new BinaryTreeInorderTraversal.TreeNode(1); 27 | Assert.assertEquals(BinaryTreeInorderTraversal.inorderTraversal(treeNode), Arrays.asList(1)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Name: Syed Ammar Ali Shah, GitHub: ammaralii 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/dsa/bit_manipulation/NonRepeatingElementInArrayElementsRepeatingKthTime.java: -------------------------------------------------------------------------------- 1 | package dsa.bit_manipulation; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Two non repeating element in array
    7 | * Find the two non repeating element in array, where every element repeat twice 8 | */ 9 | public class NonRepeatingElementInArrayElementsRepeatingKthTime { 10 | public static Integer find(List list, int k) { 11 | Integer result = list.get(0) ^ list.get(1); 12 | Integer binarySum = Integer.valueOf(Integer.toBinaryString(list.get(0))) + Integer.valueOf(Integer.toBinaryString(list.get(1))); 13 | for (int i = 2; i < list.size(); i++) { 14 | result = result ^ list.get(i); 15 | binarySum += Integer.valueOf(Integer.toBinaryString(list.get(i))); 16 | } 17 | char[] binarySumBits = String.valueOf(binarySum).toCharArray(); 18 | StringBuilder resultBits = new StringBuilder(""); 19 | for (char c : binarySumBits) { 20 | Integer temp = Integer.valueOf(c); 21 | resultBits.append(temp % k); 22 | } 23 | return Integer.parseInt(resultBits.toString(), 2); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/dictionaries_and_hashmaps/RansomNote.java: -------------------------------------------------------------------------------- 1 | package hackerrank.dictionaries_and_hashmaps; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class RansomNote { 8 | public static void checkMagazine(List magazine, List note) { 9 | System.out.println(checkMagazineUsingMap(magazine, note)); 10 | } 11 | 12 | public static String checkMagazineUsingMap(List magazine, List note) { 13 | Map magazineMap = new HashMap<>(); 14 | for (String string: magazine) { 15 | magazineMap.put(string, magazineMap.getOrDefault(string, 0) + 1); 16 | } 17 | for (String string : note) { 18 | if(magazineMap.containsKey(string)){ 19 | Integer frequency = magazineMap.get(string); 20 | if (frequency > 1){ 21 | magazineMap.put(string, frequency - 1); 22 | } else { 23 | magazineMap.remove(string); 24 | } 25 | } else { 26 | return "No"; 27 | } 28 | } 29 | return "Yes"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/interviews/amazon/coding_challenge_hackerrank/questions/Question2Test.java: -------------------------------------------------------------------------------- 1 | package interviews.amazon.coding_challenge_hackerrank.questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class Question2Test { 7 | /** 8 | * Explanation 9 | *
    A few examples of how you can pick the products (1 -based index): 10 | *
  • Choose subarray from indices (1, 2) and pick products [2, 9] respectively from each index, which is 11 products.
  • 11 | *
  • Choose subarray from indices (1, 4) and pick products [2, 3, 4, 7] , which is 16 products.
  • 12 | *
  • Choose subarray from indices (1, 5) and pick products [1, 2, 3, 4, 5], which is 15 products.
  • 13 | */ 14 | @Test 15 | public void success_findMaxProducts_test_0() { 16 | Assert.assertEquals(Question2.findMaxProducts(new int[]{2,9,4,7,5,2}), 16); 17 | } 18 | 19 | /** 20 | * Explanation 21 | *
    Take all the products as they already are in increasing order 22 | */ 23 | @Test 24 | public void success_findMaxProducts_test_1() { 25 | Assert.assertEquals(Question2.findMaxProducts(new int[]{2,5,6,7}), 20); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/search/HashTablesIceCreamParlorTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.search; 2 | 3 | import org.junit.Test; 4 | import utils.CaptureOutput; 5 | 6 | import java.util.Arrays; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | public class HashTablesIceCreamParlorTest { 11 | @Test 12 | public void success_whatFlavors_test_0() { 13 | assertEquals("1 4\n", CaptureOutput.captureStandardOutput(() -> HashTablesIceCreamParlor.whatFlavors(Arrays.asList(1, 4, 5, 3, 2), 4))); 14 | } 15 | 16 | @Test 17 | public void success_whatFlavors_test_1() { 18 | assertEquals("1 2\n", CaptureOutput.captureStandardOutput(() -> HashTablesIceCreamParlor.whatFlavors(Arrays.asList(2, 2, 4, 3), 4))); 19 | } 20 | 21 | @Test 22 | public void success_whatFlavors_test_2() { 23 | assertEquals("1 3\n", CaptureOutput.captureStandardOutput(() -> HashTablesIceCreamParlor.whatFlavors(Arrays.asList(7, 2, 5, 4, 11), 12))); 24 | } 25 | 26 | @Test 27 | public void failure_whatFlavors_test_0() { 28 | assertEquals("Error: no two flavors add up to the total cost.\n", CaptureOutput.captureStandardOutput(() -> HashTablesIceCreamParlor.whatFlavors(Arrays.asList(2,2,5), 8))); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.interview_preparation_kit 8 | com.interview_preparation_kit 9 | 1.0-SNAPSHOT 10 | interview_preparation_kit 11 | 12 | 13 | junit 14 | junit 15 | 4.13.2 16 | test 17 | 18 | 19 | com.google.code.gson 20 | gson 21 | 2.8.9 22 | 23 | 24 | 25 | 26 | 11 27 | 11 28 | UTF-8 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/test/java/interviews/avenue_code/coding_challenge_hackerrank/questions/Section2Question1Test.java: -------------------------------------------------------------------------------- 1 | package interviews.avenue_code.coding_challenge_hackerrank.questions; 2 | 3 | import org.junit.Test; 4 | 5 | import static interviews.avenue_code.coding_challenge_hackerrank.questions.Section2Question1.bestUniversityByCountry; 6 | 7 | public class Section2Question1Test { 8 | @Test 9 | public void success_StringChallenge_test_cases() { 10 | // Test case 1 11 | String input1 = "India"; 12 | String expectedOutput1 = "Indian Institute of Technology Bombay (IITB)"; 13 | String output1 = bestUniversityByCountry(input1); 14 | assert output1.equals(expectedOutput1) : "Test Case 1 Failed"; 15 | 16 | // Test case 2 17 | String input2 = "United Kingdom"; 18 | String expectedOutput2 = "University of Oxford"; 19 | String output2 = bestUniversityByCountry(input2); 20 | assert output2.equals(expectedOutput2) : "Test Case 2 Failed"; 21 | 22 | // Test case 3 23 | String input3 = "North Korea"; 24 | String expectedOutput3 = ""; 25 | String output3 = bestUniversityByCountry(input3); 26 | assert output3.equals(expectedOutput3) : "Test Case 3 Failed"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/amazon_questions/interviewbit/WaysToDecode.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | public class WaysToDecode { 4 | public static int find(String A) { 5 | int n = A.length(); 6 | char digits[] = A.toCharArray(); 7 | 8 | // A table to store results of subproblems 9 | int count[] = new int[n + 1]; 10 | count[0] = 1; 11 | count[1] = 1; 12 | if(digits[0]=='0') //for base condition "01123" should return 0 13 | return 0; 14 | for (int i = 2; i <= n; i++) 15 | { 16 | count[i] = 0; 17 | 18 | // If the last digit is not 0, 19 | // then last digit must add to 20 | // the number of words 21 | if (digits[i - 1] > '0') 22 | count[i] = count[i - 1]; 23 | 24 | // If second last digit is smaller 25 | // than 2 and last digit is smaller 26 | // than 7, then last two digits 27 | // form a valid character 28 | if (digits[i - 2] == '1' || 29 | (digits[i - 2] == '2' && 30 | digits[i - 1] < '7')) 31 | count[i] += count[i - 2]; 32 | } 33 | return count[n]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/interviews/aurora_solutions/coding_challenge_coderbyte/question/Question1.java: -------------------------------------------------------------------------------- 1 | package interviews.aurora_solutions.coding_challenge_coderbyte.question; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class Question1 { 7 | public static String StringChallenge(String str) { 8 | String[] words = str.split(" "); 9 | 10 | for (int i = 0; i < words.length; i++) { 11 | String word = words[i]; 12 | Set digits = new HashSet(); 13 | int adjacentCount = 0; 14 | 15 | for (int j = 0; j < word.length(); j++) { 16 | char ch = word.charAt(j); 17 | if (Character.isDigit(ch)) { 18 | int digit = Character.getNumericValue(ch); 19 | digits.add(digit); 20 | if (j > 0 && Character.isDigit(word.charAt(j-1)) && Math.abs(Character.getNumericValue(word.charAt(j-1)) - digit) == 1) { 21 | adjacentCount++; 22 | } 23 | } 24 | } 25 | 26 | if (digits.size() != 3 || adjacentCount == 3) { 27 | return "false"; 28 | } 29 | } 30 | 31 | return "true"; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/arrays/TwoDArrayDS.java: -------------------------------------------------------------------------------- 1 | package hackerrank.arrays; 2 | 3 | import java.util.List; 4 | 5 | public class TwoDArrayDS { 6 | /* 7 | * Complete the 'hourglassSum' function below. 8 | * 9 | * The function is expected to return an INTEGER. 10 | * The function accepts 2D_INTEGER_ARRAY arr as parameter. 11 | */ 12 | 13 | public static int hourglassSum(List> arr) { 14 | Integer max = Integer.MIN_VALUE; 15 | for (int i = 0; i < 4; i++) { 16 | List arr1 = arr.get(i); 17 | List arr2 = arr.get(i + 1); 18 | List arr3 = arr.get(i + 2); 19 | for(int j=0;j<4;j++) { 20 | System.out.println(arr1.get(j) + " " + arr1.get(j + 1) + " " + arr1.get(j + 2)); 21 | System.out.println(" " + arr2.get(j + 1)); 22 | System.out.println(arr3.get(j) + " " + arr3.get(j + 1) + " " + arr3.get(j + 2)); 23 | Integer sum = arr1.get(j) + arr1.get(j + 1) + arr1.get(j + 2) + arr2.get(j + 1) + arr3.get(j) + arr3.get(j + 1) + arr3.get(j + 2); 24 | if (sum > max) { 25 | max = sum; 26 | } 27 | } 28 | } 29 | return max; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/interviews/teamapt/online_assessment/questions/Question2Test.java: -------------------------------------------------------------------------------- 1 | package interviews.teamapt.online_assessment.questions; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.io.IOException; 7 | 8 | public class Question2Test { 9 | /**price - ((discount / 100f) * price) 10 | * Explanation
    11 | *
  • First, a call is made to API https://jsonmock.hackerrank.com/api/inventory?barcode=74002314. The 12 | * price = 3705 and discount = 20.
  • 13 | */ 14 | @Test 15 | public void success_getDiscountedPrice_test_0() throws IOException { 16 | Assert.assertEquals(Question2.getDiscountedPrice(74002314), 2964); 17 | } 18 | 19 | /** 20 | * Explanation
    21 | *
  • First, a call is made to API https://jsonmock.hackerrank.com/api/inventory?barcode=74002314. The data 22 | * field contains an empty array, so the item was not found.
  • 23 | */ 24 | @Test 25 | public void success_getDiscountedPrice_test_1() throws IOException { 26 | Assert.assertEquals(Question2.getDiscountedPrice(74005364), -1); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/interviews/glovo/live_coding_interview/Readme.md: -------------------------------------------------------------------------------- 1 | ### Question 1 2 | Write a function to check whether two given strings are anagrams of each 3 | other. An anagram of a string is another string that contains the same 4 | characters, only the order of characters can be different. 5 | 6 | **Examples:** 7 | ``` 8 | Input: 9 | s1="ABCD" 10 | s2="DABC" 11 | 12 | Return: 13 | true 14 | ``` 15 | 16 | ``` 17 | Input: 18 | s1="AABB" 19 | s2="BBAA" 20 | 21 | Return: 22 | true 23 | ``` 24 | 25 | ``` 26 | Input: 27 | s1="AAAB" 28 | s2="AABB" 29 | 30 | Return: 31 | false 32 | ``` 33 | 34 | ### Question 2 35 | Write an algorithm that given a string containing any combination of the characters 36 | '(', ')', '{', '}', '[' and ']', determines if the input string is valid. 37 | 38 | An input string is valid when: 39 | 40 | - Opening parentheses are closed by the same type of closing parentheses, and 41 | - Opening parentheses are closed in the correct order. 42 | 43 | **Examples:** 44 | ``` 45 | Input: 46 | string="()" 47 | 48 | Return: 49 | true 50 | ``` 51 | 52 | ``` 53 | Input: 54 | string="()[]{}" 55 | 56 | Return: 57 | true 58 | ``` 59 | 60 | ``` 61 | Input: 62 | string="(]" 63 | 64 | Return: 65 | false 66 | ``` 67 | 68 | ``` 69 | Input: 70 | string="([)])" 71 | 72 | Return: 73 | false 74 | ``` -------------------------------------------------------------------------------- /src/main/java/leetcode/RomanToInteger.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | public class RomanToInteger { 4 | public static int romanToInt(String s) { 5 | int nums[]=new int[s.length()]; 6 | for(int i=0;i s1Freq = new HashMap<>(); 12 | for (char c:s1.toCharArray()){ 13 | s1Freq.put(String.valueOf(c), s1Freq.getOrDefault(String.valueOf(c), 0) + 1); 14 | } 15 | System.out.println(s1Freq); 16 | for (char c: s2.toCharArray()){ 17 | if (s1Freq.containsKey(String.valueOf(c))){ 18 | Integer occur = s1Freq.get(String.valueOf(c)); 19 | if (occur>1){ 20 | s1Freq.put(String.valueOf(c), occur - 1); 21 | } else { 22 | s1Freq.remove(String.valueOf(c)); 23 | } 24 | } 25 | } 26 | if (s1Freq.size()>0){ 27 | return false; 28 | } else { 29 | return true; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/dictionaries_and_hashmaps/RansomNoteTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.dictionaries_and_hashmaps; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class RansomNoteTest { 10 | @Test 11 | public void success_checkMagazineUsingMap_example() { 12 | List magazine = Arrays.asList("give", "me", "one", "grand", "today", "night"); 13 | List note = Arrays.asList("give", "one", "grand", "today"); 14 | Assert.assertEquals(RansomNote.checkMagazineUsingMap(magazine, note), "Yes"); 15 | } 16 | 17 | @Test 18 | public void success_checkMagazineUsingMap_test_0() { 19 | List magazine = Arrays.asList("two", "times", "three", "is", "not", "four"); 20 | List note = Arrays.asList("two", "times", "two", "is", "four"); 21 | Assert.assertEquals(RansomNote.checkMagazineUsingMap(magazine, note), "No"); 22 | } 23 | 24 | @Test 25 | public void success_checkMagazineUsingMap_test_1() { 26 | List magazine = Arrays.asList("ive", "got", "a", "lovely", "bunch", "of", "coconuts"); 27 | List note = Arrays.asList("ive", "got", "some", "coconuts"); 28 | Assert.assertEquals(RansomNote.checkMagazineUsingMap(magazine, note), "No"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/amazon_questions/interviewbit/MaxProductSubarray.java: -------------------------------------------------------------------------------- 1 | package amazon_questions.interviewbit; 2 | 3 | import java.util.List; 4 | 5 | public class MaxProductSubarray { 6 | public static Integer find(List list) { 7 | // max positive product 8 | // ending at the current position 9 | Integer max_ending_here = list.get(0); 10 | 11 | // min negative product ending 12 | // at the current position 13 | Integer min_ending_here = list.get(0); 14 | 15 | // Initialize overall max product 16 | Integer max_so_far = list.get(0); 17 | 18 | // /* Traverse through the array. 19 | // the maximum product subarray ending at an index 20 | // will be the maximum of the element itself, 21 | // the product of element and max product ending previously 22 | // and the min product ending previously. */ 23 | for (int i = 1; i < list.size(); i++) { 24 | Integer temp = Math.max(Math.max(list.get(i), list.get(i) * max_ending_here), list.get(i) * min_ending_here); 25 | min_ending_here = Math.min(Math.min(list.get(i), list.get(i) * max_ending_here), list.get(i) * min_ending_here); 26 | max_ending_here = temp; 27 | max_so_far = Math.max(max_so_far, max_ending_here); 28 | } 29 | 30 | return max_so_far; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/interviews/teamapt/online_assessment/questions/Question1.java: -------------------------------------------------------------------------------- 1 | package interviews.teamapt.online_assessment.questions; 2 | 3 | public class Question1 { 4 | public static int balancedSum(int[] arr) { 5 | return solution2(arr); 6 | } 7 | 8 | //This is how I solved it 9 | private static int solution1(int[] arr){ 10 | int leftptr = 0; 11 | int rightptr = arr.length - 1; 12 | int left_sum = arr[leftptr]; 13 | int right_sum = arr[rightptr]; 14 | while (rightptr - leftptr != 2) { 15 | if (left_sum <= right_sum) { 16 | leftptr++; 17 | left_sum = left_sum + arr[leftptr]; 18 | } else { 19 | rightptr--; 20 | right_sum = right_sum + arr[rightptr]; 21 | } 22 | } 23 | if (left_sum == right_sum) { 24 | return (leftptr + 1); 25 | } else { 26 | return -1; 27 | } 28 | } 29 | 30 | //Best Algorithm 31 | private static int solution2(int[] arr){ 32 | int totalSum = 0; 33 | for (int i = 0; i < arr.length; i++) { 34 | totalSum += arr[i]; 35 | } 36 | for (int i = 1; i < arr.length -1; i++) { 37 | if ((totalSum - arr[i])%2==0){ 38 | return i; 39 | } 40 | } 41 | return -1; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/arrays/TwoDArrayDSTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.arrays; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | public class TwoDArrayDSTest { 11 | @Test 12 | public void success_jumpingOnClouds_example() { 13 | List> arr = new ArrayList<>(); 14 | arr.add(Arrays.asList(-9,-9,-9,1,1,1)); 15 | arr.add(Arrays.asList(0,-9,0,4,3,2)); 16 | arr.add(Arrays.asList(-9,-9,-9,1,2,3)); 17 | arr.add(Arrays.asList(0,0,8,6,6,0)); 18 | arr.add(Arrays.asList(0,0,0,-2,0,0)); 19 | arr.add(Arrays.asList(0,0,1,2,4,0)); 20 | Assert.assertEquals(TwoDArrayDS.hourglassSum(arr), 28); 21 | } 22 | 23 | @Test 24 | public void success_jumpingOnClouds_test_0() { 25 | List> arr = new ArrayList<>(); 26 | arr.add(Arrays.asList(1,1,1,0,0,0)); 27 | arr.add(Arrays.asList(0,1,0,0,0,0)); 28 | arr.add(Arrays.asList(1,1,1,0,0,0)); 29 | arr.add(Arrays.asList(0,0,2,4,4,0)); 30 | arr.add(Arrays.asList(0,0,0,2,0,0)); 31 | arr.add(Arrays.asList(0,0,1,2,4,0)); 32 | Assert.assertEquals(TwoDArrayDS.hourglassSum(arr), 19); 33 | } 34 | 35 | @Test 36 | public void success_jumpingOnClouds_test_1() { 37 | Assert.assertEquals(1,1); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/arrays/ArrayManipulationTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.arrays; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | public class ArrayManipulationTest { 11 | @Test 12 | public void success_jumpingOnClouds_example() { 13 | List> arr = new ArrayList<>(); 14 | arr.add(Arrays.asList(1, 2, 100)); 15 | arr.add(Arrays.asList(2, 5, 100)); 16 | arr.add(Arrays.asList(3, 4, 100)); 17 | Assert.assertEquals(ArrayManipulation.arrayManipulation(5, arr), 200); 18 | } 19 | 20 | @Test 21 | public void success_jumpingOnClouds_test_0() { 22 | List> arr = new ArrayList<>(); 23 | arr.add(Arrays.asList(1, 5, 3)); 24 | arr.add(Arrays.asList(4, 8, 7)); 25 | arr.add(Arrays.asList(6, 9, 1)); 26 | Assert.assertEquals(ArrayManipulation.arrayManipulation(10, arr), 10); 27 | } 28 | 29 | @Test 30 | public void success_jumpingOnClouds_test_1() { 31 | List> arr = new ArrayList<>(); 32 | arr.add(Arrays.asList(2, 6, 8)); 33 | arr.add(Arrays.asList(3, 5, 7)); 34 | arr.add(Arrays.asList(1, 8, 1)); 35 | arr.add(Arrays.asList(5, 9, 15)); 36 | Assert.assertEquals(ArrayManipulation.arrayManipulation(10, arr), 31); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/leetcode/MergeTwoSortedLists.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | public class MergeTwoSortedLists { 4 | public static class ListNode { 5 | int val; 6 | ListNode next; 7 | 8 | public ListNode() { 9 | } 10 | 11 | ListNode(int val) { 12 | this.val = val; 13 | } 14 | 15 | ListNode(int val, ListNode next) { 16 | this.val = val; 17 | this.next = next; 18 | } 19 | } 20 | 21 | public static ListNode mergeTwoLists(ListNode list1, ListNode list2) { 22 | if(list1 == null){ 23 | return list2; 24 | } 25 | if(list2 == null){ 26 | return list1; 27 | } 28 | 29 | if (list1.val > list2.val) { 30 | ListNode temp = list2; 31 | list2 = list1; 32 | list1 = temp; 33 | } 34 | ListNode realHead = list1; 35 | while (list1.next != null && list2 != null) { 36 | if (list1.next.val <= list2.val) { 37 | list1 = list1.next; 38 | } else { 39 | ListNode temp = list1.next; 40 | list1.next = list2; 41 | list2 = list2.next; 42 | list1.next.next = temp; 43 | list1 = list1.next; 44 | } 45 | } 46 | if (list2 != null) list1.next = list2; 47 | return realHead; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/amazon_questions/KLargestOrSmallestElements.java: -------------------------------------------------------------------------------- 1 | package amazon_questions; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * k largest(or smallest) elements in an array
    9 | * Write an efficient program for printing k largest elements in an array. Elements in an array can be in any order. 10 | */ 11 | public class KLargestOrSmallestElements { 12 | public enum KLargestOrSmallestElementsEnum { 13 | SMALLEST, LARGEST 14 | } 15 | 16 | /** 17 | * @param list 18 | * @param k 19 | * @param value 20 | * @return 21 | */ 22 | public static List kSmallestOrLargest(List list, Integer k, KLargestOrSmallestElementsEnum value) { 23 | if (list.isEmpty()) { 24 | return list; 25 | } 26 | list = list.stream().sorted().collect(Collectors.toList()); 27 | List result = new ArrayList<>(); 28 | if (value.equals(KLargestOrSmallestElementsEnum.SMALLEST)) { 29 | for (int i = 0; i < k; i++) { 30 | result.add(list.get(i)); 31 | } 32 | } else if (value.equals(KLargestOrSmallestElementsEnum.LARGEST)) { 33 | for (int i = (list.size() - k); i < list.size(); i++) { 34 | result.add(list.get(i)); 35 | } 36 | } 37 | return result; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/greedy_algorithms/ReverseShuffleMerge.java: -------------------------------------------------------------------------------- 1 | package hackerrank.greedy_algorithms; 2 | 3 | import java.util.Stack; 4 | 5 | public class ReverseShuffleMerge { 6 | public static String reverseShuffleMerge(String s) { 7 | int[] addCount = new int[26]; 8 | int[] skipCount; 9 | Stack characters = new Stack<>(); 10 | String result = ""; 11 | 12 | char[] sChar = s.toCharArray(); 13 | 14 | for (int i = 0; i < sChar.length; i++) { 15 | addCount[sChar[i] - 'a']++; 16 | } 17 | 18 | for (int i = 0; i < addCount.length; i++) { 19 | addCount[i] /= 2; 20 | } 21 | 22 | skipCount = addCount.clone(); 23 | 24 | for (int i = sChar.length - 1; i >= 0; i--) { 25 | while (!characters.empty() && characters.peek() > sChar[i] && addCount[sChar[i] - 'a'] > 0 && skipCount[characters.peek() - 'a'] > 0) { 26 | char c = characters.pop(); 27 | addCount[c - 'a']++; 28 | skipCount[c - 'a']--; 29 | } 30 | 31 | if (addCount[sChar[i] - 'a'] > 0) { 32 | characters.push(sChar[i]); 33 | addCount[sChar[i] - 'a']--; 34 | } else { 35 | skipCount[sChar[i] - 'a']--; 36 | } 37 | } 38 | 39 | while (!characters.empty()) { 40 | result = characters.pop() + result; 41 | } 42 | return result; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/amazon_questions/MissingNumberInArray.java: -------------------------------------------------------------------------------- 1 | package amazon_questions; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | 6 | /** 7 | * Find the missing number in the array
    8 | * You are given an array of positive numbers from 1 to n, such that all numbers from 1 to n are present except one 9 | * number x. You have to find x. The input array is not sorted. Look at the below array and give it a try before 10 | * checking the solution. 11 | */ 12 | public class MissingNumberInArray { 13 | //This is what most people do 14 | public static Integer findMissingNumberInArray_1(List list) { 15 | list = list.stream().sorted().collect(Collectors.toList()); 16 | 17 | for (int i = 0; i < list.size(); i++) { 18 | if (i + 1 != list.get(i)) { 19 | return list.get(i) - 1; 20 | } 21 | } 22 | return 0; 23 | } 24 | 25 | //This is optimized one 26 | public static Integer findMissingNumberInArray(List list) { 27 | if (list.isEmpty()) { 28 | return -1; 29 | } 30 | Integer size = list.size(); 31 | System.out.println(size); 32 | Integer sum = ((size + 1) * (size + 2)) / 2; 33 | for (int i = 0; i < size; i++) { 34 | sum -= list.get(i); 35 | } 36 | System.out.println(sum); 37 | if (sum == size + 1) { 38 | return -1; 39 | } 40 | return sum; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/amazon_questions/MergeTwoSortedLinkedList.java: -------------------------------------------------------------------------------- 1 | package amazon_questions; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashSet; 5 | import java.util.List; 6 | import java.util.Set; 7 | import java.util.stream.Collectors; 8 | 9 | /** 10 | * Merge Two Sorted Linked Lists
    11 | * Given two sorted lists, merge them so that the resulting list is also sorted. 12 | */ 13 | public class MergeTwoSortedLinkedList { 14 | public static List mergeTwoSortedLinkedList(List list1, List list2) { 15 | if (list1.isEmpty()) { 16 | return list2; 17 | } 18 | if (list2.isEmpty()) { 19 | return list1; 20 | } 21 | 22 | List result = new ArrayList<>(); 23 | 24 | int totalSize = list1.size() + list2.size(); 25 | int pos1 = 0; // current index in the first array 26 | int pos2 = 0; // current index in the second array 27 | 28 | for (int i = 0; i < totalSize; i++) { 29 | System.out.println("Position 1: " + pos1 + " Position 2: " + pos2); 30 | // if the second array is exhausted or if both positions are valid and the current element in the first array is the lowest 31 | if (pos2 >= list2.size() || pos1 < list1.size() && list1.get(pos1).compareTo(list2.get(pos2)) < 0) { 32 | result.add(list1.get(pos1++)); 33 | } else { 34 | result.add(list2.get(pos2++)); 35 | } 36 | } 37 | return result; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/interviews/remotebase/coding_challenge_hackerrank/questions/Question1Test.java: -------------------------------------------------------------------------------- 1 | package interviews.remotebase.coding_challenge_hackerrank.questions; 2 | 3 | import interviews.remotebase.coding_challenge_hackerrank.question.Question1; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class Question1Test { 8 | @Test 9 | public void success_rearrange_test_0() { 10 | Assert.assertArrayEquals(Question1.rearrange(new int[]{21, 34, 5, 7, 9}), new int[]{9, 21, 5, 34, 7}); 11 | } 12 | 13 | @Test 14 | public void success_rearrange_test_1() { 15 | Assert.assertArrayEquals(Question1.rearrange(new int[]{1, 2, 3, 4}), new int[]{2, 3, 1, 4}); 16 | } 17 | 18 | @Test 19 | public void success_rearrange_test_2() { 20 | Assert.assertArrayEquals(Question1.rearrange(new int[]{}), new int[]{}); 21 | } 22 | 23 | @Test 24 | public void success_rearrange_test_3() { 25 | Assert.assertArrayEquals(Question1.rearrange(new int[]{1}), new int[]{1}); 26 | } 27 | 28 | @Test 29 | public void success_rearrange_test_4() { 30 | Assert.assertArrayEquals(Question1.rearrange(new int[]{1,2}), new int[]{1,2}); 31 | } 32 | 33 | @Test 34 | public void success_rearrange_test_5() { 35 | Assert.assertArrayEquals(Question1.rearrange(new int[]{1,2,3}), new int[]{2,3,1}); 36 | } 37 | 38 | @Test 39 | public void success_rearrange_test_6() { 40 | Assert.assertArrayEquals(Question1.rearrange(new int[]{1, -2, 3, -4, 5}), new int[]{1, 3, -4, 5, -2}); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/leetcode/MergeSortedArrayTest.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | import java.util.stream.Collectors; 9 | 10 | public class MergeSortedArrayTest { 11 | @Test 12 | public void success_merge_test_0() { 13 | int[] nums1 = new int[]{1, 2, 3, 0, 0, 0}; 14 | MergeSortedArray.merge(nums1, 3, new int[]{2, 4, 6}, 3); 15 | checkMergeResult(nums1, Arrays.asList(1, 2, 2, 3, 4, 6)); 16 | } 17 | 18 | @Test 19 | public void success_merge_test_1() { 20 | int[] nums1 = new int[]{4, 5, 6, 0, 0, 0}; 21 | MergeSortedArray.merge(nums1, 3, new int[]{2, 4, 6}, 3); 22 | checkMergeResult(nums1, Arrays.asList(2, 4, 4, 5, 6, 6)); 23 | } 24 | 25 | @Test 26 | public void success_merge_test_2() { 27 | int[] nums1 = new int[]{1, 5, 6, 0, 0, 0}; 28 | MergeSortedArray.merge(nums1, 3, new int[]{2, 4, 6}, 3); 29 | checkMergeResult(nums1, Arrays.asList(1, 2, 4, 5, 6, 6)); 30 | } 31 | 32 | @Test 33 | public void success_merge_test_3() { 34 | int[] nums1 = new int[]{1, 7, 8, 9, 0, 0, 0}; 35 | MergeSortedArray.merge(nums1, 4, new int[]{2, 4, 6}, 3); 36 | checkMergeResult(nums1, Arrays.asList(1, 2, 4, 6, 7, 8, 9)); 37 | } 38 | 39 | private void checkMergeResult(int[] nums1, List actual) { 40 | List result = Arrays.stream(nums1).boxed().collect(Collectors.toList()); 41 | Assert.assertEquals(result, actual); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/dictionaries_and_hashmaps/SherLockAndAnagrams.java: -------------------------------------------------------------------------------- 1 | package hackerrank.dictionaries_and_hashmaps; 2 | 3 | import java.util.*; 4 | 5 | public class SherLockAndAnagrams { 6 | /* 7 | * Complete the 'sherlockAndAnagrams' function below. 8 | * 9 | * The function is expected to return an INTEGER. 10 | * The function accepts STRING s as parameter. 11 | */ 12 | 13 | //abcd 14 | //abc 15 | //ab,bc 16 | //a,b,b,c 17 | public static int sherlockAndAnagrams(String s) { 18 | Map anagrams = new HashMap<>(); 19 | 20 | for (int i = 0; i < s.length(); ++i) { // O(|s|) 21 | System.out.println("Index is: " + i); 22 | for (int j = 0; j < s.length() - i; ++j) { // O(|s|) 23 | System.out.println(String.format("Index i is: %d, Index j is: %d", i, j)); 24 | char[] substr = s.substring(j, j + i + 1).toCharArray(); 25 | Arrays.sort(substr); // O(|s| log|s|) 26 | System.out.println(substr); 27 | String anagram = new String(substr); 28 | anagrams.put(anagram, anagrams.getOrDefault(anagram, 0) + 1); 29 | } 30 | } 31 | 32 | int total = 0; 33 | for (int v : anagrams.values()) { // O(|k|) 34 | if (v > 1) { 35 | System.out.println(v); 36 | total += combs(v); 37 | } 38 | } 39 | return total; 40 | } 41 | 42 | public static int combs(int n) { 43 | return n * (n - 1) / 2; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/amazon_questions/SumOfTwoIntegersInArrayEqualsGivenValue.java: -------------------------------------------------------------------------------- 1 | package amazon_questions; 2 | 3 | import java.util.HashSet; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.stream.Collectors; 7 | 8 | /** 9 | * Determine if the sum of two integers is equal to the given value
    10 | * Given an array of integers and a value, determine if there are any two integers in the array whose sum is equal to 11 | * the given value. Return true if the sum exists and return false if it does not. 12 | */ 13 | public class SumOfTwoIntegersInArrayEqualsGivenValue { 14 | //This is what most people do 15 | public static boolean isSumOfTwoIntegersInArrayEqualsGivenValue_1(List list, Integer value) { 16 | list = list.stream().sorted().collect(Collectors.toList()); 17 | int counter = 1; 18 | while (counter != list.size() && list.get(counter) list, Integer value) { 31 | Set foundValues = new HashSet<>(); 32 | for (Integer a : list) { 33 | if (foundValues.contains(value - a)) { 34 | return true; 35 | } 36 | foundValues.add(a); 37 | } 38 | return false; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/interviews/remotebase/coding_challenge_hackerrank/questions/Question4Test.java: -------------------------------------------------------------------------------- 1 | package interviews.remotebase.coding_challenge_hackerrank.questions; 2 | 3 | import interviews.remotebase.coding_challenge_hackerrank.question.Question4; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class Question4Test { 8 | @Test 9 | public void success_mergePalindromes_example_0() { 10 | Assert.assertEquals(Question4.mergePalindromes("aabbc","ddefefq"), "abdefcfedba"); 11 | } 12 | 13 | @Test 14 | public void success_mergePalindromes_test_0() { 15 | Assert.assertEquals(Question4.mergePalindromes("aab","cca"), "acaca"); 16 | } 17 | 18 | @Test 19 | public void success_mergePalindromes_test_1() { 20 | Assert.assertEquals(Question4.mergePalindromes("adaab","cac"), "aaccaa"); 21 | } 22 | 23 | @Test 24 | public void success_mergePalindromes_test_2() { 25 | Assert.assertEquals(Question4.mergePalindromes("aaaabbbccc","ddeeccc"), "aabcccdeedcccbaa"); 26 | } 27 | 28 | @Test 29 | public void success_mergePalindromes_test_3() { 30 | Assert.assertEquals(Question4.mergePalindromes("awwzaigvxuikdqlvshspsvyckttwdzqmarpxglwmpob","dtisfxyobndu"), "abddgiklmpqstvwwxzzxwwvtsqpmlkigddba"); 31 | } 32 | 33 | @Test 34 | public void success_mergePalindromes_test_4() { 35 | Assert.assertEquals(Question4.mergePalindromes("mgbgikhvjyiigxhsrgekjmjkrs","cikmqfxpcybzyhbdrhudjmsoaqdurgjsnjlqogrkcmdtxbyazfxvbprimbcblpnriyvndntmpvjun"), "abbbccddfggghhiiijjjkklmmmnnoppqrrrsstuvxyyzzyyxvutssrrrqpponnmmmlkkjjjiiihhgggfddccbbba"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/string_manipulation/SherlockAndValidString.java: -------------------------------------------------------------------------------- 1 | package hackerrank.string_manipulation; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.stream.Collectors; 8 | 9 | public class SherlockAndValidString { 10 | public static String isValid(String s) { 11 | Map charFreqMap = new HashMap<>(); 12 | for (int i = 0; i < s.length(); i++) { 13 | char c = s.charAt(i); 14 | int freq = charFreqMap.getOrDefault(c, 0); 15 | charFreqMap.put(c, ++freq); 16 | } 17 | 18 | int[] arr = new int[charFreqMap.size()]; 19 | int idx = 0; 20 | for (Map.Entry characterIntegerEntry : charFreqMap.entrySet()) { 21 | arr[idx++] = characterIntegerEntry.getValue(); 22 | } 23 | Arrays.sort(arr); 24 | 25 | if (charFreqMap.size() == 1) return "YES"; 26 | 27 | int first = arr[0]; 28 | int second = arr[1]; 29 | int secondLast = arr[arr.length - 2]; 30 | int last = arr[arr.length - 1]; 31 | 32 | // If first and last are same, then all frequencies are same 33 | if (first == last) return "YES"; 34 | 35 | // If first is 1, and all other characters have 1 frequency 36 | if (first == 1 && second == last) return "YES"; 37 | 38 | // If all are same and last character has just 1 extra count 39 | if (first == second && second == secondLast && secondLast == (last - 1)) return "YES"; 40 | 41 | // Else invalid string 42 | return "NO"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/Readme.md: -------------------------------------------------------------------------------- 1 | ## JAVA DEVELOPER | SENIOR JAVA DEVELOPER | SENIOR BACKEND ENGINEER | SENIOR FULLSTACK ENGINEER 2 | Referral Link: [https://talent.remotebase.com?referral=dM5hFwLY5Weg4P1PJma4DM](https://talent.remotebase.com?referral=dM5hFwLY5Weg4P1PJma4DM) 3 | 4 | ## Domain Test 5 | ![domain_test.png](resources/domain_test.png) 6 | - Select Java as seen in above screenshot 7 | - Please check the [questions](domain_test) folder to check list of questions asked in previous domain test 8 | 9 | ## HR Screening 10 | These questions being asked: 11 | - Introduction about yourself? 12 | - how you handled a difficult situation? 13 | - What Are Your Long Term Career Goals? Why you join us. 14 | 15 | ![hr_screening.png](resources/hr_screening.png) 16 | 17 | ## Problem Solving 18 | Please check the [coding_challenge_hackerrank](coding_challenge_hackerrank) folder to check list of questions asked in previous coding Challenge HackerRank questions 19 | ![problem_solving.png](resources/problem_solving.png) 20 | 21 | ## Final Interview 22 | It's divided into three parts as per experienced: 23 | - **Not Technical - 10 to 15 mins**: (Discuss you, your experience and some behavioural questions or some scenarios) 24 | - **System Design - 20 to 30 mins**: URL Shortening Service or something similar to this 25 | - **Live Coding - 20 to 30 mins**: Please check the [live_coding_interview](live_coding_interview) folder to check list of questions asked in previous interviews 26 | ![final_interview.png](resources/final_interview.png) 27 | 28 | ## Network 29 | Once you cleared all the rounds then you will be a part of Network 30 | ![network.png](resources/network.png) 31 | 32 | 33 | Good luck with the preparation ! -------------------------------------------------------------------------------- /src/main/java/leetcode/ValidParentheses.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import java.util.ArrayDeque; 4 | import java.util.Deque; 5 | 6 | public class ValidParentheses { 7 | public static boolean isValid(String s) { 8 | // Using ArrayDeque is faster than using Stack class 9 | Deque stack = new ArrayDeque<>(); 10 | 11 | // Traversing the Expression 12 | for (int i = 0; i < s.length(); i++) { 13 | char x = s.charAt(i); 14 | 15 | if (x == '(' || x == '[' || x == '{') { 16 | // Push the element in the stack 17 | stack.push(x); 18 | continue; 19 | } 20 | 21 | // If current character is not opening 22 | // bracket, then it must be closing. So stack 23 | // cannot be empty at this point. 24 | if (stack.isEmpty()) 25 | return false; 26 | char check; 27 | switch (x) { 28 | case ')': 29 | check = stack.pop(); 30 | if (check == '{' || check == '[') 31 | return false; 32 | break; 33 | 34 | case '}': 35 | check = stack.pop(); 36 | if (check == '(' || check == '[') 37 | return false; 38 | break; 39 | 40 | case ']': 41 | check = stack.pop(); 42 | if (check == '(' || check == '{') 43 | return false; 44 | break; 45 | } 46 | } 47 | 48 | // Check Empty Stack 49 | return (stack.isEmpty()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/interviews/amazon/Readme.md: -------------------------------------------------------------------------------- 1 | ## BACKEND ENGINEER | Software Development Engineer 2 | 3 | ## Hackerrank Coding Session 4 | 5 | ### INSTRUCTION 6 | 7 | Thank you for your continued interest in Amazon's Software Development Engineer (SDE) opportunities! We are excited to move you forward in the application process. As the next step, we'd like to invite you to complete this online assessment no later than a week from now. 8 | 9 | At Amazon, we hire the best minds in technology to innovate and build on behalf of our customers. The intense focus we have on our customers is the reason we are one of the world's most beloved brands – customer obsession is part of our company DNA. Amazonians chart their own path by owning their development, their career, and their future. What unites Amazonians across teams and geographies is that we are all striving to delight our customers and make their lives easier. The scope and scale of our mission drives us to seek diverse perspectives, be resourceful, and navigate through ambiguity. By working together on behalf of our customers, we are building the future one innovative product, service, and idea at a time. 10 | 11 | **Overview** 12 | 13 | There are 3 types of exercises in the assessment: 14 | 15 | 1. Coding Challenge – this timed section takes 90 minutes, work through two coding problems. 16 | 2. Work Simulation – typically takes 15 minutes, work through software development decisions faced by SDEs at Amazon. 17 | 3. Work Style Surveys – typically takes 10 minutes, 2 surveys - answer questions about how you approach software engineering work and your approach to work in general. 18 | 19 | Please check the [questions](coding_challenge_hackerrank) folder to check list of questions asked in previous coding challenges -------------------------------------------------------------------------------- /src/main/java/interviews/glovo/Readme.md: -------------------------------------------------------------------------------- 1 | ## BACKEND ENGINEER | SENIOR FULLSTACK ENGINEER 2 | 3 | ## Live Coding Session 4 | 5 | ### INSTRUCTION 6 | 7 | Below is an outline of what to expect and recommended preparation for 8 | the Live Coding interview. 9 | 10 | In this interview you will be expected to solve small 11 | problems. The interview focuses on algorithms and data 12 | structures. You’ll be expected to know and apply: lists, 13 | maps, stacks, priority queues, trees, graphs, bags, and 14 | sets. You’ll need to be able to talk about how they’re 15 | implemented and why you’d choose one 16 | implementation or data structure instead of another. 17 | For algorithms, you’ll need to know greedy algorithms, 18 | divide and conquer, dynamic programming, recursion, 19 | backtracking, and brute force search. You’ll definitely 20 | need to be familiar with Big O notation, running time 21 | and space complexity. 22 | 23 | Additionally, you'll be asked to answer some technical 24 | questions related to algorithms, data structures and 25 | testing 26 | 27 | **Important:** Please bring your laptop and an IDE 28 | prepared with an empty project already setup in a 29 | framework of your choice, so that you can write and 30 | execute your solution, with unit tests. **We expect you 31 | to write test cases. So, don't forget to setup the unit 32 | tests frameworks of your choice.** You will be sharing 33 | your screen to show your work to the interviewers. 34 | 35 | We hope this helps & whilst we appreciate that it's a lot of information, 36 | we’d rather you be over prepared than under-prepared. 37 | 38 | Good luck with the preparation ! 39 | 40 | Please check the [questions](live_coding_interview) folder to check list of questions asked in previous live coding interviews -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/live_coding_interview/Readme.md: -------------------------------------------------------------------------------- 1 | ### Question 1 (Pattern Searching) 2 | 3 | #### Description 4 | 5 | Suppose that we have a text and a pattern. We need to determine if the pattern exists in the text or not. 6 | 7 | For example: 8 | ``` 9 | +-------+---+---+---+---+---+---+---+---+ 10 | | Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | +-------+---+---+---+---+---+---+---+---+ 12 | | Text | a | b | c | b | c | g | l | x | 13 | +-------+---+---+---+---+---+---+---+---+ 14 | +---------+---+---+---+---+ 15 | | Index | 0 | 1 | 2 | 16 | +---------+---+---+---+---+ 17 | | Pattern | g | l | x | 18 | +---------+---+---+---+---+ 19 | ``` 20 | The algorithm that you are going to write searches for occurrences of a "Pattern" within a main "Text" by employing the observation that when a mismatch occurs, the word itself embodies sufficient information to determine where the next match could begin, thus bypassing re-examination of previously matched characters.
Give me a detailed pseudo code of how it will work and what is its time complexity of worst case and best case? What about the space complexity? 21 | 22 | ### Sample Test Cases 23 | #### Test Case 1: 24 | ##### Sample Input 25 | ``` 26 | text = "abcbcglx" 27 | pattern = "glx" 28 | ``` 29 | 30 | ##### Sample Output 31 | ``` 32 | Found pattern at index 5 33 | ``` 34 | 35 | #### Test Case 2: 36 | ##### Sample Input 37 | ``` 38 | text = "abcabcxyzabcxxyzyxyz" 39 | pattern = "xyz" 40 | ``` 41 | 42 | ##### Sample Output 43 | ``` 44 | Found pattern at index 6 45 | Found pattern at index 13 46 | Found pattern at index 17 47 | ``` 48 | 49 | #### Test Case 3: 50 | ##### Sample Input 51 | ``` 52 | text = "abcdef ghijkl" 53 | pattern = "xyz" 54 | ``` 55 | 56 | ##### Sample Output 57 | ``` 58 | No Pattern Found 59 | ``` -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/coding_challenge_hackerrank/question/Question4.java: -------------------------------------------------------------------------------- 1 | package interviews.remotebase.coding_challenge_hackerrank.question; 2 | 3 | import java.util.Arrays; 4 | 5 | public class Question4 { 6 | /* 7 | * Complete the 'mergePalindromes' function below. 8 | * 9 | * The function is expected to return a STRING. 10 | * The function accepts following parameters: 11 | * 1. STRING s1 12 | * 2. STRING s2 13 | */ 14 | public static String mergePalindromes(String s1, String s2) { 15 | int[] countA = new int[26]; 16 | int[] countB = new int[26]; 17 | 18 | for (char ch : s1.toCharArray()) { 19 | countA[ch - 'a'] += 1; 20 | } 21 | 22 | for (char ch : s2.toCharArray()) { 23 | countB[ch - 'a'] += 1; 24 | } 25 | 26 | String mid = ""; 27 | String res = ""; 28 | for (int i = 0; i < 26; i++) { 29 | 30 | char curr = (char) (i + 'a'); 31 | 32 | if (countA[i] % 2 == 1 && countB[i] % 2 == 1 && mid.length() < 2) { 33 | mid = String.valueOf(curr) + curr; 34 | } 35 | 36 | if ((countA[i] % 2 == 1 || countB[i] % 2 == 1) && mid.length() == 0) { 37 | mid = String.valueOf(curr); 38 | } 39 | 40 | res += new String(new char[countA[i] / 2 + countB[i] / 2]).replace("\0", String.valueOf(curr)); 41 | 42 | } 43 | 44 | if (mid.length() == 2) { 45 | char[] resChars = (res + mid.charAt(0)).toCharArray(); 46 | Arrays.sort(resChars); 47 | res = new String(resChars); 48 | return res + new StringBuilder(res).reverse(); 49 | } 50 | 51 | return res + mid + new StringBuilder(res).reverse(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/greedy_algorithms/LuckBalanceTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.greedy_algorithms; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | public class LuckBalanceTest { 11 | @Test 12 | public void success_luckBalance_test_0() { 13 | List> contests = new ArrayList<>(); 14 | contests.add(Arrays.asList(5,1)); 15 | contests.add(Arrays.asList(2,1)); 16 | contests.add(Arrays.asList(1,1)); 17 | contests.add(Arrays.asList(8,1)); 18 | contests.add(Arrays.asList(10,0)); 19 | contests.add(Arrays.asList(5,0)); 20 | Assert.assertEquals(LuckBalance.luckBalance(3, contests), 29); 21 | } 22 | 23 | @Test 24 | public void success_luckBalance_test_1() { 25 | List> contests = new ArrayList<>(); 26 | contests.add(Arrays.asList(13,1)); 27 | contests.add(Arrays.asList(10,1)); 28 | contests.add(Arrays.asList(9,1)); 29 | contests.add(Arrays.asList(8,1)); 30 | contests.add(Arrays.asList(13,1)); 31 | contests.add(Arrays.asList(12,1)); 32 | contests.add(Arrays.asList(18,1)); 33 | contests.add(Arrays.asList(13,1)); 34 | Assert.assertEquals(LuckBalance.luckBalance(5, contests), 42); 35 | } 36 | 37 | @Test 38 | public void success_luckBalance_test_2() { 39 | List> contests = new ArrayList<>(); 40 | contests.add(Arrays.asList(5,1)); 41 | contests.add(Arrays.asList(4,0)); 42 | contests.add(Arrays.asList(6,1)); 43 | contests.add(Arrays.asList(2,1)); 44 | contests.add(Arrays.asList(8,0)); 45 | Assert.assertEquals(LuckBalance.luckBalance(2, contests), 21); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/amazon_questions/PythagoreanTriplet.java: -------------------------------------------------------------------------------- 1 | package amazon_questions; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | 6 | /** 7 | * Pythagorean Triplet in an array
    8 | * Given an array of integers, write a function that returns true if there is a triplet (a, b, c) that satisfies 9 | * a2 + b2 = c2. 10 | */ 11 | public class PythagoreanTriplet { 12 | //This is what most people do 13 | public static boolean isTriplet_1(List list) { 14 | int size = list.size(); 15 | for (int i = 0; i < size; i++) { 16 | for (int j = 0; j < size; j++) { 17 | for (int k = 0; k < size; k++) { 18 | int a = list.get(i); 19 | int b = list.get(j); 20 | int c = list.get(k); 21 | if (a * a + b * b == c * c) { 22 | return true; 23 | } 24 | } 25 | } 26 | } 27 | return false; 28 | } 29 | 30 | //This is optimized one 31 | public static boolean isTriplet(List list) { 32 | if (list.size() < 3) { 33 | return false; 34 | } 35 | list = list.stream().map(l -> l * l).sorted().collect(Collectors.toList()); 36 | int aIndex = 0; 37 | int bIndex = list.size() - 2; 38 | int cIndex = list.size() - 1; 39 | while (aIndex != bIndex) { 40 | if (list.get(cIndex) == list.get(aIndex) + list.get(bIndex)) { 41 | return true; 42 | } 43 | if (aIndex + 1 == bIndex) { 44 | bIndex--; 45 | cIndex--; 46 | aIndex = 0; 47 | } else { 48 | aIndex++; 49 | } 50 | } 51 | return false; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/warm_up_challenges/JumpingOnTheClouds.md: -------------------------------------------------------------------------------- 1 | There is a new mobile game that starts with consecutively numbered clouds. Some of the clouds are thunderheads and 2 | others are cumulus. The player can jump on any cumulus cloud having a number that is equal to the number of the current 3 | cloud plus 1 or 2. The player must avoid the thunderheads. Determine the minimum number of jumps it will take to jump 4 | from the starting postion to the last cloud. It is always possible to win the game. 5 | 6 | For each game, you will get an array of clouds numbered 0 if they are safe or 1 if they smust be avoided. 7 | 8 | **Example** 9 | 10 | c=[0,1,0,0,0,1,0] 11 | 12 | Index the array from 0...6. The number on each cloud is its index in the list so the player must avoid the clouds at 13 | indices 1 and 5. They could follow these two paths: 0->2->4->6 or 0->2->3->4->6. The first path takes 3 jumps while the second takes 4. Return 3. 14 | 15 | **Function Description** 16 | 17 | Complete the jumpingOnClouds function in the editor below. 18 | 19 | jumpingOnClouds has the following parameter(s): 20 | 21 | - int c[n]: an array of binary integers 22 | 23 | **Returns** 24 | 25 | - int: the minimum number of jumps required 26 | 27 | **Input Format** 28 | 29 | The first line contains an integer n, the total number of clouds. The second line contains n space-separated binary 30 | integers describing clouds c[i] where 0<=i processingPower, List bootingPower, Integer maxPower) { 8 | if (processingPower == null || bootingPower == null || processingPower.size() == 0 || processingPower.size() != bootingPower.size()) { 9 | return 0; 10 | } 11 | PriorityQueue maxBootingPower = new PriorityQueue<>((a, b) -> Integer.compare(b, a)); 12 | Integer maximumSustainableClusterSize = 0; 13 | Integer currentLength = 1; 14 | Integer start = 0; 15 | Integer end = 0; 16 | Integer currentSumProcessingPower = processingPower.get(0); 17 | maxBootingPower.add(bootingPower.get(0)); 18 | while (end < processingPower.size()) { 19 | Integer currentBootingPower = maxBootingPower.peek(); 20 | Integer currentPower = currentBootingPower + currentSumProcessingPower * currentLength; 21 | if (currentPower <= maxPower) { 22 | maximumSustainableClusterSize = currentLength; 23 | end++; 24 | currentLength++; 25 | } else { 26 | currentSumProcessingPower -= processingPower.get(start); 27 | maxBootingPower.remove(bootingPower.get(start)); 28 | start++; 29 | end++; 30 | } 31 | if (end < processingPower.size()) { 32 | maxBootingPower.add(bootingPower.get(end)); 33 | currentSumProcessingPower += processingPower.get(end); 34 | } 35 | } 36 | return maximumSustainableClusterSize; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/coding_challenge_hackerrank/question/Question1.java: -------------------------------------------------------------------------------- 1 | package interviews.remotebase.coding_challenge_hackerrank.question; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class Question1 { 8 | public static int[] rearrange(int[] arr) { 9 | // Sorting the array 10 | Arrays.sort(arr); 11 | 12 | // Taking the size of the array in an arraySize variable 13 | int arraySize = arr.length; 14 | 15 | // If the size of the array is less than 16 | // or equals to 2 then we return 17 | // because we just multiply the first and second element 18 | if (arraySize <= 2) { 19 | return arr; 20 | } 21 | 22 | // Declaring a vector to store answers 23 | List ans = new ArrayList<>(); 24 | int k = 0, j; 25 | 26 | // If the size of the array is even then the value of j 27 | // becomes array size minus one divided by 2 28 | // else j becomes array size divided by 2 29 | if (arraySize % 2 == 0) { 30 | j = (arraySize - 1) / 2; 31 | } else { 32 | j = arraySize / 2; 33 | } 34 | 35 | // First we push back the jth element into the answer vector 36 | ans.add(arr[j]); 37 | j++; 38 | ans.add(arr[j]); 39 | j++; 40 | 41 | for (int i = 2; i < arraySize; i++) { 42 | // If it is even then we push back the kth element 43 | // else we push back jth element 44 | if (i % 2 == 0) { 45 | ans.add(arr[k]); 46 | k++; 47 | } else { 48 | ans.add(arr[j]); 49 | j++; 50 | } 51 | } 52 | 53 | // Return 54 | return ans.stream().mapToInt(Integer::intValue).toArray(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/interviews/teamapt/online_assessment/questions/Question2.java: -------------------------------------------------------------------------------- 1 | package interviews.teamapt.online_assessment.questions; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.JsonArray; 5 | import com.google.gson.JsonElement; 6 | import com.google.gson.JsonObject; 7 | 8 | import java.io.BufferedReader; 9 | import java.io.IOException; 10 | import java.io.InputStreamReader; 11 | import java.net.HttpURLConnection; 12 | import java.net.URL; 13 | 14 | public class Question2 { 15 | private static final String URL = 16 | "https://jsonmock.hackerrank.com/api/inventory?barcode="; 17 | 18 | /* 19 | * Complete the 'getDiscountedPrice' function below. 20 | * 21 | * The function is expected to return an INTEGER. 22 | * The function accepts INTEGER barcode as parameter. 23 | * API URL: https://jsonmock.hackerrank.com/api/inventory?barcode= 24 | 25 | */ 26 | public static int getDiscountedPrice(int barcode) throws IOException { 27 | java.net.URL obj = new URL(URL + barcode); 28 | HttpURLConnection con = (HttpURLConnection) obj.openConnection(); 29 | con.setRequestMethod("GET"); 30 | BufferedReader in = new BufferedReader(new 31 | InputStreamReader(con.getInputStream())); 32 | String response; 33 | while ((response = in.readLine()) != null) { 34 | JsonObject jsonResponse = new Gson().fromJson(response, 35 | JsonObject.class); 36 | JsonArray data = jsonResponse.getAsJsonArray("data"); 37 | for (JsonElement e : data) { 38 | int discount = e.getAsJsonObject().get("discount").getAsInt(); 39 | int price = e.getAsJsonObject().get("price").getAsInt(); 40 | return Math.round(price - ((discount / 100f) * price)); 41 | } 42 | } 43 | return -1; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/leetcode/BinaryTreeInorderTraversal.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Stack; 6 | 7 | public class BinaryTreeInorderTraversal { 8 | public static class TreeNode { 9 | int val; 10 | TreeNode left; 11 | 12 | TreeNode right; 13 | 14 | TreeNode() { 15 | } 16 | 17 | TreeNode(int val) { 18 | this.val = val; 19 | } 20 | 21 | TreeNode(int val, TreeNode left, TreeNode right) { 22 | this.val = val; 23 | this.left = left; 24 | this.right = right; 25 | } 26 | } 27 | 28 | public static List inorderTraversal(TreeNode root) { 29 | List result = new ArrayList<>(); 30 | inorderTraversalHelperUsingRecursive(root, result); 31 | return result; 32 | } 33 | 34 | private static void inorderTraversalHelperUsingRecursive(TreeNode node, List result) { 35 | if (node == null) 36 | return; 37 | 38 | //first recur on left child 39 | inorderTraversalHelperUsingRecursive(node.left, result); 40 | 41 | //Add node data to List 42 | result.add(node.val); 43 | 44 | //now recur on right child 45 | inorderTraversalHelperUsingRecursive(node.right, result); 46 | } 47 | 48 | private static void inorderTraversalHelperUsingStack(TreeNode node, List result) { 49 | Stack stack = new Stack<>(); 50 | TreeNode current = node; 51 | while (current != null || !stack.isEmpty()) { 52 | while (current != null) { 53 | stack.push(current); 54 | current = current.left; 55 | } 56 | current = stack.pop(); 57 | result.add(current.val); 58 | current = current.right; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/arrays/MinimumSwapsTwo.java: -------------------------------------------------------------------------------- 1 | package hackerrank.arrays; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | public class MinimumSwapsTwo { 8 | public static int minimumSwaps(int[] arr) { 9 | return minimumSwapsUsingCustomAlgo(arr); 10 | } 11 | 12 | private static int minimumSwapsUsingCustomAlgo(int[] arr) { 13 | int n = arr.length - 1; 14 | int minSwaps = 0; 15 | for (int i = 0; i < n; i++) { 16 | if (i < arr[i] - 1) { 17 | System.out.println(Math.min(n, arr[i] - 1)); 18 | swap(arr, i, Math.min(n, arr[i] - 1)); 19 | minSwaps++; 20 | i--; 21 | } 22 | printArray(arr); 23 | } 24 | return minSwaps; 25 | } 26 | 27 | public static void printArray(int[] arr) { 28 | List list = Arrays.stream(arr).boxed().collect(Collectors.toList()); 29 | System.out.println("Array is: " + list); 30 | } 31 | 32 | private static void swap(int[] array, int i, int j) { 33 | int temp = array[i]; 34 | array[i] = array[j]; 35 | array[j] = temp; 36 | } 37 | 38 | private static int minimumSwapsUsingSelectionSort(int arr[]) { 39 | int count = 0; 40 | for (int i = 0; i < arr.length - 1; i++) { 41 | int index = 0, smallest = Integer.MAX_VALUE; 42 | for (int j = i; j < arr.length; j++) { 43 | if (arr[j] < smallest) { 44 | smallest = arr[j]; 45 | index = j; 46 | } 47 | } 48 | if (i != index) { 49 | int toSwipe = arr[i]; 50 | int withSwipe = smallest; 51 | arr[i] = withSwipe; 52 | arr[index] = toSwipe; 53 | count++; 54 | } 55 | } 56 | return count; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/leetcode/MergeTwoSortedListsTest.java: -------------------------------------------------------------------------------- 1 | package leetcode; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class MergeTwoSortedListsTest { 7 | @Test 8 | public void success_mergeTwoLists_test_0() { 9 | MergeTwoSortedLists.ListNode list1 = new MergeTwoSortedLists.ListNode( 10 | 1, new MergeTwoSortedLists.ListNode(2, new MergeTwoSortedLists.ListNode(4)) 11 | ); 12 | MergeTwoSortedLists.ListNode list2 = new MergeTwoSortedLists.ListNode( 13 | 1, new MergeTwoSortedLists.ListNode(3, new MergeTwoSortedLists.ListNode(4)) 14 | ); 15 | MergeTwoSortedLists.ListNode result = MergeTwoSortedLists.mergeTwoLists(list1, list2); 16 | MergeTwoSortedLists.ListNode actual = new MergeTwoSortedLists.ListNode( 17 | 1, new MergeTwoSortedLists.ListNode(1, new MergeTwoSortedLists.ListNode( 18 | 2, new MergeTwoSortedLists.ListNode(3, new MergeTwoSortedLists.ListNode( 19 | 4, new MergeTwoSortedLists.ListNode(4))))) 20 | ); 21 | while (actual != null && result!=null){ 22 | Assert.assertEquals(result.val, actual.val); 23 | result = result.next; 24 | actual = actual.next; 25 | } 26 | } 27 | 28 | @Test 29 | public void success_mergeTwoLists_test_1() { 30 | MergeTwoSortedLists.ListNode list1 = new MergeTwoSortedLists.ListNode(2); 31 | MergeTwoSortedLists.ListNode list2 = new MergeTwoSortedLists.ListNode(1); 32 | MergeTwoSortedLists.ListNode result = MergeTwoSortedLists.mergeTwoLists(list1, list2); 33 | MergeTwoSortedLists.ListNode actual = new MergeTwoSortedLists.ListNode(1, new MergeTwoSortedLists.ListNode(2)); 34 | while (actual != null && result!=null){ 35 | Assert.assertEquals(result.val, actual.val); 36 | result = result.next; 37 | actual = actual.next; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/interviews/remotebase/live_coding_interview/questions/Question1Test.java: -------------------------------------------------------------------------------- 1 | package interviews.remotebase.live_coding_interview.questions; 2 | 3 | import org.junit.Test; 4 | import utils.CaptureOutput; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | public class Question1Test { 9 | @Test 10 | public void success_search_test_0() { 11 | String pattern = "glx"; 12 | String text = "abcbcglx"; 13 | String exceptedOutput = "Found pattern at index 5\n"; 14 | String actual = CaptureOutput.captureStandardOutput(() -> Question1.search(pattern, text)); 15 | assertEquals(exceptedOutput, actual); 16 | } 17 | 18 | @Test 19 | public void success_search_test_1() { 20 | String pattern = "xyz"; 21 | String text = "abcabcxyzabcxxyzyxyz"; 22 | String exceptedOutput = "Found pattern at index 6\n" + 23 | "Found pattern at index 13\n" + 24 | "Found pattern at index 17\n"; 25 | String actual = CaptureOutput.captureStandardOutput(() -> Question1.search(pattern, text)); 26 | assertEquals(exceptedOutput, actual); 27 | } 28 | 29 | @Test 30 | public void success_search_test_2() { 31 | String pattern = "Magic"; 32 | String text = "hello it's me Magic. Do you know what Magic is in this repo"; 33 | String exceptedOutput = "Found pattern at index 14\n" + 34 | "Found pattern at index 38\n"; 35 | String actual = CaptureOutput.captureStandardOutput(() -> Question1.search(pattern, text)); 36 | assertEquals(exceptedOutput, actual); 37 | } 38 | 39 | @Test 40 | public void failure_search_test_0() { 41 | String pattern = "xyz"; 42 | String text = "abcdef ghijkl"; 43 | String exceptedOutput = "No Pattern Found\n"; 44 | String actual = CaptureOutput.captureStandardOutput(() -> Question1.search(pattern, text)); 45 | assertEquals(exceptedOutput, actual); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/coding_challenge_hackerrank/question/Question3.java: -------------------------------------------------------------------------------- 1 | package interviews.remotebase.coding_challenge_hackerrank.question; 2 | 3 | import java.util.Map; 4 | import java.util.LinkedHashMap; 5 | import java.util.List; 6 | import java.util.ArrayList; 7 | import java.util.Collections; 8 | 9 | public class Question3 { 10 | /** 11 | * @param s 12 | * @return string: the lexicographically smallest string s can be changed to 13 | */ 14 | public static String getString(String s) { 15 | char[] sChar = s.toCharArray(); 16 | int str_len = s.length(); 17 | char[] res = new char[str_len]; 18 | Map> charDict = new LinkedHashMap<>(); 19 | Map> charDictOld = new LinkedHashMap<>(); 20 | 21 | for (int i = 0; i < sChar.length; i++) { 22 | char ch = sChar[i]; 23 | if (!charDict.containsKey(ch)) { 24 | charDict.put(ch, new ArrayList<>()); 25 | charDict.get(ch).add(i); 26 | charDictOld.put(ch, new ArrayList<>()); 27 | charDictOld.get(ch).add(i); 28 | } else { 29 | charDict.get(ch).add(i); 30 | charDictOld.get(ch).add(i); 31 | } 32 | } 33 | 34 | List keys = new ArrayList<>(charDict.keySet()); 35 | Collections.sort(keys); 36 | 37 | List> dictValue = new ArrayList<>(); 38 | for (char i : charDictOld.keySet()) { 39 | dictValue.add(charDictOld.get(i)); 40 | } 41 | 42 | int dictIndex = 0; 43 | for (char i : keys) { 44 | charDict.put(i, dictValue.get(dictIndex)); 45 | dictIndex++; 46 | } 47 | 48 | for (char i : keys) { 49 | for (int index : charDict.get(i)) { 50 | res[index] = i; 51 | } 52 | } 53 | 54 | return new String(res); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/hackerrank/dictionaries_and_hashmaps/FrequencyQueriesTest.java: -------------------------------------------------------------------------------- 1 | package hackerrank.dictionaries_and_hashmaps; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | public class FrequencyQueriesTest { 11 | @Test 12 | public void success_freqQuery_example_0() { 13 | List> queries = new ArrayList<>(); 14 | queries.add(Arrays.asList(1,5)); 15 | queries.add(Arrays.asList(1,6)); 16 | queries.add(Arrays.asList(3,2)); 17 | queries.add(Arrays.asList(1,10)); 18 | queries.add(Arrays.asList(1,10)); 19 | queries.add(Arrays.asList(1,6)); 20 | queries.add(Arrays.asList(2,5)); 21 | queries.add(Arrays.asList(3,2)); 22 | Assert.assertEquals(FrequencyQueries.freqQuery(queries), Arrays.asList(0,1)); 23 | } 24 | 25 | @Test 26 | public void success_freqQuery_example_1() { 27 | List> queries = new ArrayList<>(); 28 | queries.add(Arrays.asList(3,4)); 29 | queries.add(Arrays.asList(2,1003)); 30 | queries.add(Arrays.asList(1,16)); 31 | queries.add(Arrays.asList(3,1)); 32 | Assert.assertEquals(FrequencyQueries.freqQuery(queries), Arrays.asList(0,1)); 33 | } 34 | 35 | @Test 36 | public void success_freqQuery_example_2() { 37 | List> queries = new ArrayList<>(); 38 | queries.add(Arrays.asList(1,3)); 39 | queries.add(Arrays.asList(2,3)); 40 | queries.add(Arrays.asList(3,2)); 41 | queries.add(Arrays.asList(1,4)); 42 | queries.add(Arrays.asList(1,5)); 43 | queries.add(Arrays.asList(1,5)); 44 | queries.add(Arrays.asList(1,4)); 45 | queries.add(Arrays.asList(3,2)); 46 | queries.add(Arrays.asList(2,4)); 47 | queries.add(Arrays.asList(3,2)); 48 | Assert.assertEquals(FrequencyQueries.freqQuery(queries), Arrays.asList(0,1,1)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/interviews/remotebase/coding_challenge_hackerrank/questions/Question2Test.java: -------------------------------------------------------------------------------- 1 | package interviews.remotebase.coding_challenge_hackerrank.questions; 2 | 3 | import interviews.remotebase.coding_challenge_hackerrank.question.Question2; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class Question2Test { 8 | @Test 9 | public void success_countTeams_test_0() { 10 | int[] skills = {12, 4, 6, 13, 5, 10}; 11 | int minPlayers = 3; 12 | int minLevel = 4; 13 | int maxLevel = 10; 14 | Assert.assertEquals(Question2.countTeams(skills, minPlayers, minLevel, maxLevel), 5); 15 | } 16 | 17 | @Test 18 | public void success_countTeams_test_1() { 19 | int[] skills = new int[] {4, 8, 5, 6}; 20 | int minPlayers = 1; 21 | int minLevel = 5; 22 | int maxLevel = 7; 23 | Assert.assertEquals(Question2.countTeams(skills, minPlayers, minLevel, maxLevel), 3); 24 | } 25 | 26 | @Test 27 | public void success_countTeams_test_2() { 28 | int[] skills = new int[] {4, 8, 5, 6}; 29 | int minPlayers = 2; 30 | int minLevel = 5; 31 | int maxLevel = 7; 32 | Assert.assertEquals(Question2.countTeams(skills, minPlayers, minLevel, maxLevel), 1); 33 | } 34 | 35 | @Test 36 | public void success_countTeams_test_3() { 37 | int[] skills = new int[]{}; 38 | int minPlayers = 3; 39 | int minLevel = 4; 40 | int maxLevel = 10; 41 | Assert.assertEquals(Question2.countTeams(skills, minPlayers, minLevel, maxLevel), 0); 42 | } 43 | 44 | @Test 45 | public void success_countTeams_test_4() { 46 | int[] skills = new int[] {4, 5, 6, 7, 8}; 47 | int minPlayers = 5; 48 | int minLevel = 4; 49 | int maxLevel = 8; 50 | Assert.assertEquals(Question2.countTeams(skills, minPlayers, minLevel, maxLevel), 1); 51 | } 52 | 53 | @Test 54 | public void success_countTeams_test_5() { 55 | int[] skills = new int[] {4, 5, 6, 7, 8}; 56 | int minPlayers = 2; 57 | int minLevel = 9; 58 | int maxLevel = 10; 59 | Assert.assertEquals(Question2.countTeams(skills, minPlayers, minLevel, maxLevel), 0); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/sorting/MergeSortCountingInversions.java: -------------------------------------------------------------------------------- 1 | package hackerrank.sorting; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class MergeSortCountingInversions { 7 | public static long countInversions(List arr) { 8 | int n = arr.size(); 9 | int inv_count = 0; 10 | for (int i = 0; i < n - 1; i++) { 11 | for (int j = i + 1; j < n; j++) { 12 | if (arr.get(i) > arr.get(j)) { 13 | swap(arr, i, j); 14 | inv_count++; 15 | } 16 | } 17 | } 18 | System.out.println(arr); 19 | 20 | return inv_count; 21 | } 22 | 23 | private static void swap(List array, int i, int j) { 24 | int temp = array.get(i); 25 | array.set(i, array.get(j)); 26 | array.set(j, temp); 27 | } 28 | 29 | public static long countInversionsOptimized(List arr) { 30 | List aux = new ArrayList<>(arr); 31 | return sort(arr, 0, arr.size() - 1, aux); 32 | } 33 | 34 | private static long sort(List array, int left, int right, List aux) { 35 | if (left >= right) { 36 | return 0; 37 | } 38 | int mid = (left + right) / 2; 39 | long a = sort(aux, left, mid, array); 40 | long b = sort(aux, mid + 1, right, array); 41 | long c = merge(array, left, mid, right, aux); 42 | return a + b + c; 43 | } 44 | 45 | private static long merge(List array, int left, int mid, int right, 46 | List aux) { 47 | int idx = left; 48 | int left1 = left; 49 | int right1 = mid; 50 | int left2 = mid + 1; 51 | int right2 = right; 52 | long count = 0; 53 | while (left1 <= right1 && left2 <= right2) { 54 | if (aux.get(left1) <= aux.get(left2)) { 55 | array.set(idx++, aux.get(left1)); 56 | left1++; 57 | } else { 58 | array.set(idx++, aux.get(left2)); 59 | count += (mid - left1 + 1); 60 | left2++; 61 | } 62 | } 63 | while (left1 <= right1) { 64 | array.set(idx++, aux.get(left1)); 65 | left1++; 66 | } 67 | while (left2 <= right2) { 68 | array.set(idx++, aux.get(left2)); 69 | left2++; 70 | } 71 | return count; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/interviews/teamapt/online_assessment/Readme.md: -------------------------------------------------------------------------------- 1 | ### Question 1 2 | Given an array of numbers, find the index of the smallest array element (the pivot), for which the sums of 3 | all elements to the left and to the right are equal. The array may not be reordered. 4 | 5 | **Example** 6 | 7 | arr=[1,2,3,4,6] 8 | 9 | - the sum of the first three elements, 1+2+3=6. The value of the last element is 6. 10 | - Using zero based indexing, arr[3]=4 is the pivot between the two subarrays. 11 | - The index of the pivot is 3. 12 | 13 | **Function Description** 14 | 15 | Complete the function balancedSum in the editor below. 16 | 17 | balancedSum has the following parameter(s): 18 | 19 | int arr[n]: an array of integers 20 | 21 | Returns: 22 | 23 | int: an integer representing the index of the pivot 24 | 25 | **Constraints** 26 | - 3 ≤ n ≤ 105 27 | - 1 ≤ arr[i] ≤ 2 × 104, where 0 ≤ i < n 28 | - It is guaranteed that a solution always exists. 29 | 30 | ### Question 2 31 | Given a barcode, query the API at https://jsonmock.hackerrank.com/api/inventory?barcode=barcode and 32 | return the item's discounted price. 33 | 34 | The response is a JSON object with 5 fields. The essential field is data: 35 | - data: Either an empty array or an array with a single object that contains the item's record. 36 | - In the data array, the item has the following schema: 37 | - barcode - the barcode for the product (String) 38 | - price - the gross selling price (Number) 39 | - discount: the discount percent to apply (Number). 40 | - Some fields that are not of interest. 41 | 42 | page, per_page, total, total_pages, etc. are not required for this task. 43 | 44 | If the barcode is found, the data array contains exactly 1 element. If not, it is empty and the function should 45 | return '-1'. 46 | 47 | An example of the product record from https://jsonmock.hackerrank.com/api/inventory?barcode=74001755 is: 48 | 49 | ```json 50 | { 51 | "barcode": "74001755", 52 | "item": "Ball Gown", 53 | "category": "Full Body Outfits", 54 | "price": 785, 55 | "discount": 7, 56 | "available": 1 57 | } 58 | ``` 59 | 60 | Use the "discount" and the "price" properties to calculate the discounted price rounded to the nearest 61 | integer. 62 | 63 | discountedPrice = price - ((discount / 100) * price) 64 | 65 | **Function Description** 66 | 67 | Complete the getDiscountedPrice function in the editor. 68 | 69 | getDiscountedPrice has the following parameters: 70 | 71 | string barcode: the item to query 72 | 73 | **Returns** 74 | 75 | int: the discounted price rounded to the nearest integer or -1 76 | 77 | **Constraints** 78 | - There will be either 1 or 0 records in data. 79 | -------------------------------------------------------------------------------- /src/main/java/hackerrank/dictionaries_and_hashmaps/FrequencyQueries.java: -------------------------------------------------------------------------------- 1 | package hackerrank.dictionaries_and_hashmaps; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public class FrequencyQueries { 9 | //- 1 x : Insert x in your data structure. 10 | //- 2 y : Delete one occurence of y from your data structure, if present. 11 | //- 3 z : Check if any integer is present whose frequency is exactly . If yes, print 1 else 0. 12 | public static List freqQuery(List> queries) { 13 | List result = new ArrayList<>(); 14 | Map queriesValuesMap = new HashMap<>(); 15 | Map freqMap = new HashMap<>(); 16 | for (List query : queries) { 17 | Integer queryKey = query.get(0); 18 | Integer queryValue = query.get(1); 19 | if (queryKey.equals(1)){ 20 | Integer value = queriesValuesMap.getOrDefault(queryValue, 0); 21 | queriesValuesMap.put(queryValue, value + 1); 22 | freqMap.put(value, freqMap.getOrDefault(value, 0) - 1); 23 | freqMap.put(value + 1, freqMap.getOrDefault(value + 1, 0) + 1); 24 | } else if (queryKey.equals(2)){ 25 | Integer value = queriesValuesMap.getOrDefault(queryValue, 0); 26 | if (value>1){ 27 | queriesValuesMap.put(queryValue, value - 1); 28 | freqMap.put(value, freqMap.getOrDefault(value, 0) - 1); 29 | freqMap.put(value - 1, freqMap.getOrDefault(value - 1, 0) + 1); 30 | } else { 31 | queriesValuesMap.remove(queryValue); 32 | freqMap.put(value, freqMap.getOrDefault(value, 0) - 1); 33 | } 34 | } else if (queryKey.equals(3)){ 35 | Integer value = freqMap.getOrDefault(queryValue, 0); 36 | if (value > 0){ 37 | result.add(1); 38 | } else { 39 | result.add(0); 40 | } 41 | //Optimized using Freq map addition 42 | // if (queriesValuesMap.size()>0) { 43 | // boolean exists = queriesValuesMap.entrySet().stream().anyMatch(d->d.getValue().equals(queryValue)); 44 | // if (exists) { 45 | // result.add(1); 46 | // } else { 47 | // result.add(0); 48 | // } 49 | // } else { 50 | // result.add(0); 51 | // } 52 | } 53 | } 54 | return result; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/interviews/amazon/coding_challenge_hackerrank/questions/Question1.java: -------------------------------------------------------------------------------- 1 | package interviews.amazon.coding_challenge_hackerrank.questions; 2 | 3 | import java.util.*; 4 | 5 | public class Question1 { 6 | public static int maxSetSize(int[] riceBags) { 7 | return solution2(riceBags); 8 | } 9 | 10 | /** 11 | * Firstly I solved it using this solution but 7 test cases are failing due to timeout as you see in traverse 2 nested 12 | * loops which is causing impact so check the solution2 to check how I optimized it. 13 | *
    Complexity: O(n^2) 14 | */ 15 | private static int solution1(int[] riceBags) { 16 | //sort the lst in increasing order 17 | Arrays.sort(riceBags); 18 | 19 | int n = riceBags.length; 20 | // create a dp array of size n and initialise values with 1 21 | int[] dp = new int[n]; 22 | Arrays.fill(dp, 1); 23 | 24 | //traverse lst from i=0 to end of lst 25 | for (int i = 0; i < n; i++) { 26 | //traverse lst from j=i-1 to 0 27 | for (int j = i - 1; j > -1; j--) { 28 | //if following condition passes, then update dp[i] with max(dp[i], dp[j]+1) 29 | if (riceBags[j] * riceBags[j] == riceBags[i]) { 30 | dp[i] = Math.max(dp[i], 1 + dp[j]); 31 | } 32 | } 33 | } 34 | 35 | Arrays.stream(dp).forEach(System.out::println); 36 | 37 | OptionalInt max = Arrays.stream(dp).max(); 38 | 39 | 40 | //if max(dp) == 1, then return -1 41 | if (max.getAsInt() == 1) { 42 | return -1; 43 | } 44 | 45 | //else return max(dp) which is the max perfect set size 46 | return max.getAsInt(); 47 | } 48 | 49 | /** 50 | * as sorting is happening and java use merge sort so complexity of merge sort is 51 | *
    Complexity: O(nlog(n)) 52 | */ 53 | private static int solution2(int[] riceBags) { 54 | Arrays.sort(riceBags); 55 | 56 | Map riceBagsSetMap = new HashMap<>(); 57 | for (int i = riceBags.length - 1; i >= 0; i--) { 58 | int product = riceBags[i] * riceBags[i]; 59 | if (riceBagsSetMap.containsKey(product)) { 60 | int value = riceBagsSetMap.get(product); 61 | riceBagsSetMap.remove(product); 62 | riceBagsSetMap.put(riceBags[i], value + 1); 63 | } else { 64 | riceBagsSetMap.put(riceBags[i], 1); 65 | } 66 | } 67 | System.out.println(riceBagsSetMap); 68 | return Collections.max(riceBagsSetMap.entrySet(), Comparator.comparingInt(Map.Entry::getValue)).getValue(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/interviews/remotebase/live_coding_interview/questions/Question1.java: -------------------------------------------------------------------------------- 1 | package interviews.remotebase.live_coding_interview.questions; 2 | 3 | public class Question1 { 4 | public static void search(String pattern, String txt) 5 | { 6 | int M = pattern.length(); 7 | int N = txt.length(); 8 | 9 | // create lps[] that will hold the longest 10 | // prefix suffix values for pattern 11 | int lps[] = new int[M]; 12 | int j = 0; // index for pat[] 13 | 14 | // Preprocess the pattern (calculate lps[] 15 | // array) 16 | computeLPSArray(pattern, M, lps); 17 | 18 | int i = 0; // index for txt[] 19 | boolean notFound = true; 20 | while ((N - i) >= (M - j)) { 21 | if (pattern.charAt(j) == txt.charAt(i)) { 22 | j++; 23 | i++; 24 | } 25 | if (j == M) { 26 | System.out.println("Found pattern " 27 | + "at index " + (i - j)); 28 | notFound = false; 29 | j = lps[j - 1]; 30 | } 31 | 32 | // mismatch after j matches 33 | else if (i < N 34 | && pattern.charAt(j) != txt.charAt(i)) { 35 | // Do not match lps[0..lps[j-1]] characters, 36 | // they will match anyway 37 | if (j != 0) 38 | j = lps[j - 1]; 39 | else 40 | i = i + 1; 41 | } 42 | } 43 | if (notFound){ 44 | System.out.println("No Pattern Found"); 45 | } 46 | } 47 | 48 | private static void computeLPSArray(String pat, int M, int lps[]) 49 | { 50 | // length of the previous longest prefix suffix 51 | int len = 0; 52 | int i = 1; 53 | lps[0] = 0; // lps[0] is always 0 54 | 55 | // the loop calculates lps[i] for i = 1 to M-1 56 | while (i < M) { 57 | if (pat.charAt(i) == pat.charAt(len)) { 58 | len++; 59 | lps[i] = len; 60 | i++; 61 | } 62 | else // (pat[i] != pat[len]) 63 | { 64 | // This is tricky. Consider the example. 65 | // AAACAAAA and i = 7. The idea is similar 66 | // to search step. 67 | if (len != 0) { 68 | len = lps[len - 1]; 69 | 70 | // Also, note that we do not increment 71 | // i here 72 | } 73 | else // if (len == 0) 74 | { 75 | lps[i] = len; 76 | i++; 77 | } 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/java/dsa/mathematics_and_number_theory/FactorialTest.java: -------------------------------------------------------------------------------- 1 | package dsa.mathematics_and_number_theory; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.math.BigInteger; 7 | 8 | public class FactorialTest { 9 | @Test 10 | public void success_find_test_0() { 11 | Assert.assertTrue(Factorial.find(BigInteger.valueOf(5)).equals("120")); 12 | } 13 | 14 | @Test 15 | public void success_find_test_1() { 16 | Assert.assertTrue(Factorial.find(BigInteger.valueOf(10)).equals("3628800")); 17 | } 18 | 19 | @Test 20 | public void success_find_test_2() { 21 | Assert.assertTrue(Factorial.find(BigInteger.valueOf(1000)).equals( 22 | "402387260077093773543702433923003985719374864210714632543799910429938512398629020592044208486969404800479988610197196058631666872994808558901323829669944590997424504087073759918823627727188732519779505950995276120874975462497043601418278094646496291056393887437886487337119181045825783647849977012476632889835955735432513185323958463075557409114262417474349347553428646576611667797396668820291207379143853719588249808126867838374559731746136085379534524221586593201928090878297308431392844403281231558611036976801357304216168747609675871348312025478589320767169132448426236131412508780208000261683151027341827977704784635868170164365024153691398281264810213092761244896359928705114964975419909342221566832572080821333186116811553615836546984046708975602900950537616475847728421889679646244945160765353408198901385442487984959953319101723355556602139450399736280750137837615307127761926849034352625200015888535147331611702103968175921510907788019393178114194545257223865541461062892187960223838971476088506276862967146674697562911234082439208160153780889893964518263243671616762179168909779911903754031274622289988005195444414282012187361745992642956581746628302955570299024324153181617210465832036786906117260158783520751516284225540265170483304226143974286933061690897968482590125458327168226458066526769958652682272807075781391858178889652208164348344825993266043367660176999612831860788386150279465955131156552036093988180612138558600301435694527224206344631797460594682573103790084024432438465657245014402821885252470935190620929023136493273497565513958720559654228749774011413346962715422845862377387538230483865688976461927383814900140767310446640259899490222221765904339901886018566526485061799702356193897017860040811889729918311021171229845901641921068884387121855646124960798722908519296819372388642614839657382291123125024186649353143970137428531926649875337218940694281434118520158014123344828015051399694290153483077644569099073152433278288269864602789864321139083506217095002597389863554277196742822248757586765752344220207573630569498825087968928162753848863396909959826280956121450994871701244516461260379029309120889086942028510640182154399457156805941872748998094254742173582401063677404595741785160829230135358081840096996372524230560855903700624271243416909004153690105933983835777939410970027753472000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/interviews/aurora_solutions/coding_challenge_coderbyte/Readme.md: -------------------------------------------------------------------------------- 1 | # Question 1 (String Challenge) 2 | ## Description 3 | Have the function **StringChallenge(str)** take the **str** parameter being passed and determine if exactly three unique, 4 | single-digit integers occur within each word in the string. The integers can appear anywhere in the word, but they cannot 5 | be all adjacent to each other. If every word contains exactly 3 unique integers somewhere within it, then return the 6 | string true, otherwise return the string false. For example: if **str** is `"2hell6o3 wor6l7d2"` then your program 7 | should return `"true"` but if the string is `"hell268o w6or2l4d"` then your program should return `"false"` because all 8 | the integers are adjacent to each other in the first word. 9 | 10 | ### Examples 11 | Input: "2a3b5 w1o2rl3d g1gg92" 12 | Output: true 13 | 14 | Input: "21aa3a ggg4g4g6ggg" 15 | Output: false 16 | 17 | # Question 2 (String Challenge) 18 | ## Description 19 | Have the function **StringChallenge(str)** insert dashes `('-')` between each two odd numbers in **str**. For example: 20 | if str is `454793` the output should be `4547-9-3`. Don't count zero as an odd number. 21 | 22 | ### Examples 23 | Input: 99946 24 | Output: 9-9-946 25 | 26 | Input: 56730 27 | Output: 567-30 28 | 29 | # Question 3 (Array Challenge) 30 | ## Description 31 | Have the function **ArrayChallenge(arr)** take the array of integers stored in **arr**, and for each element in the list, 32 | search all the previous values for the nearest element that is smaller than (or equal to) the current element and create 33 | a new list from these numbers. If there is no element before a certain position that is smaller, input a -1. For example: 34 | if **arr** is `[5, 2, 8, 3, 9, 12]` then the nearest smaller values list is `[-1, -1, 2, 2, 3, 9]`. The logic is as follows: 35 | 36 | For `5`, there is no smaller previous value so the list so far is `[-1]`. For `2`, there is also no smaller previous 37 | value, so the list is now `[-1, -1]`. For `8`, the nearest smaller value is `2` so the list is now `[-1, -1, 2]`. For `3`, 38 | the nearest smaller value is also `2`, so the list is now `[-1, -1, 2, 2]`. This goes on to produce the answer above. 39 | Your program should take this final list and return the elements as a string separated by a space: `-1 -1 2 2 3 9` 40 | 41 | ### Examples 42 | Input: [5, 3, 1, 9, 7, 3, 4, 1] 43 | Output: -1 -1 -1 1 1 1 3 1 44 | 45 | Input: [2, 4, 5, 1, 7] 46 | Output: -1 2 4 -1 1 47 | 48 | # Question 4 (Array Challenge) 49 | ## Description 50 | Have the function **ArrayChallenge(arr)** take the array of numbers stored in **arr** and return the string `true` if 51 | any combination of numbers in the array (excluding the largest number) can be added up to equal the largest number in 52 | the array, otherwise return the string `false`. For example: if **arr** contains `[4, 6, 23, 10, 1, 3]` the output 53 | should return `true` because 4 + 6 + 10 + 3 = 23. The array will not be empty, will not contain all the same elements, 54 | and may contain negative numbers. 55 | 56 | ### Examples 57 | Input: [5,7,16,1,2] 58 | Output: false 59 | 60 | Input: [3,5,-1,8,12] 61 | Output: true 62 | --------------------------------------------------------------------------------