├── _config.yml ├── SQL └── BasicSelect │ ├── select-all-sql.sql │ ├── select-by-id.sql │ ├── weather-observation-station-1.sql │ ├── japanese-cities-name.sql │ ├── japanese-cities-attributes.sql │ ├── weather-observation-station-3.sql │ ├── revising-the-select-query.sql │ ├── revising-the-select-query-2.sql │ └── weather-observation-station-4.sql ├── Java ├── Introduction │ ├── JavaInttoString.java │ ├── WelcometoJava!.java │ ├── JavaStaticInitializerBlock.java │ ├── JavaEnd-of-file.java │ ├── JavaStdinandStdoutI.java │ ├── JavaLoopsI.java │ ├── JavaIf-Else.java │ ├── JavaLoopsII.java │ ├── JavaOutputFormatting.java │ ├── JavaStdinandStdoutII.java │ ├── JavaDateandTime.java │ └── JavaDatatypes.java ├── Strings │ ├── ValidUsernameRegularExpression.java │ ├── JavaRegex.java │ ├── JavaSubstring.java │ ├── JavaStringReverse.java │ ├── JavaStringTokens.java │ ├── PatternSyntaxChecker.java │ ├── JavaStringsIntroduction.java │ ├── JavaAnagrams.java │ ├── JavaSubstringComparisons.java │ ├── TagContentExtractor.java │ └── JavaRegex2-DuplicateWords.java ├── ObjectOrientedProgramming │ ├── JavaMethodOverriding.java │ ├── JavaInheritanceII.java │ ├── JavaInterface.java │ ├── JavaInheritanceI.java │ ├── JavaMethodOverriding2(SuperKeyword).java │ └── JavaAbstractClass.java ├── DataStructures │ ├── JavaGenerics.java │ ├── Java1DArray.java │ ├── JavaComparator.java │ ├── JavaHashset.java │ ├── Java2DArray.java │ ├── JavaSubarray.java │ ├── JavaMap.java │ ├── JavaArraylist.java │ ├── Java1DArray(Part2).java │ └── JavaList.java ├── Advanced │ ├── JavaFactoryPattern.java │ ├── CanYouAccess?.java │ ├── JavaVarargs-SimpleAddition.java │ ├── JavaSingletonPattern.java │ ├── JavaReflection-Attributes.java │ ├── PrimeChecker.java │ ├── JavaSHA-256.java │ └── JavaMD5.java ├── ExceptionHandling │ ├── JavaExceptionHandling.java │ ├── README.md │ └── JavaExceptionHandling(Try-catch).java └── BigNumber │ ├── JavaBigInteger.java │ ├── JavaPrimalityTest.java │ ├── README.md │ └── JavaBigDecimal.java ├── .gitignore ├── Databases └── RelationalAlgebra │ ├── basics-of-sets-and-relational-algebra-1 │ ├── basics-of-sets-and-relational-algebra-2 │ ├── basics-of-sets-and-relational-algebra-3 │ ├── basics-of-sets-and-relational-algebra-5 │ ├── basics-of-sets-and-relational-algebra-6 │ ├── basics-of-sets-and-relational-algebra-7 │ └── basics-of-sets-and-relational-algebra-4 ├── LinuxShell └── Bash │ ├── bash-tutorials-lets-echo.sh │ ├── bash-tutorials---a-personalized-echo.sh │ ├── bash-tutorials---looping-and-skipping.sh │ ├── bash-tutorials---looping-with-numbers.sh │ ├── bash-tutorials---the-world-of-numbers.sh │ ├── bash-tutorials---getting-started-with-conditionals.sh │ ├── bash-tutorials---more-on-conditionals.sh │ └── bash-tutorials---comparing-numbers.sh ├── .github └── FUNDING.yml ├── Regex ├── Backreferences │ ├── branch-reset-groups.php │ ├── ForwardReferences.java │ ├── MatchingSameTextAgain&Again.java │ ├── BackreferencesToFailedGroups.java │ └── README.md ├── Introduction │ ├── MatchingSpecificString.java │ ├── MatchingAnythingButaNewline.java │ ├── MatchingStart&End.java │ ├── MatchingDigits&Non-DigitCharacters.java │ ├── MatchingWhitespace&Non-WhitespaceCharacter.java │ └── MatchingWord&Non-WordCharacter.java ├── Assertions │ ├── PositiveLookahead.java │ ├── NegativeLookahead.java │ ├── PositiveLookbehind.java │ ├── NegativeLookbehind.java │ └── README.md ├── Repetitions │ ├── MatchingEndingItems.java │ ├── MatchingOneOrMoreRepetitions.java │ ├── MatchingZeroOrMoreRepetitions.java │ ├── Matching{x}Repetitions.java │ ├── Matching{x,y}Repetitions.java │ └── README.md ├── GroupingandCapturing │ ├── Capturing&Non-CapturingGroups.java │ ├── AlternativeMatching.java │ ├── MatchingWordBoundaries.java │ └── README.md └── CharacterClass │ ├── MatchingCharacterRanges.java │ ├── MatchingSpecificCharacters.java │ ├── ExcludingSpecificCharacters.java │ └── README.md ├── Security ├── Functions │ ├── SecurityFunctions.java │ ├── SecurityFunctionsII.java │ ├── SecurityPermutations.java │ ├── SecurityFunctionInverses.java │ ├── SecurityBijectiveFunctions.java │ └── SecurityInvolution.java ├── Cryptography │ └── README.md └── TerminologyandConcepts │ ├── SecurityEncryptionScheme.java │ ├── Security-MessageSpaceandCiphertextSpace.java │ ├── SecurityKeySpaces.java │ └── README.md ├── Tutorials ├── 30DaysofCode │ ├── Day22:BinarySearchTrees.java │ ├── Day17:MoreExceptions.java │ ├── Day19:Interfaces.java │ ├── Day15:LinkedList.java │ ├── Day13:AbstractClasses.java │ ├── Day21:Generics.java │ ├── Day5:Loops.java │ ├── Day14:Scope.java │ ├── Day18:QueuesandStacks.java │ ├── Day9:Recursion3.java │ ├── Day16:Exceptions-StringtoInteger.java │ ├── Day24:MoreLinkedLists.java │ ├── Day0:Hello,World..java │ ├── Day1:DataTypes.java │ ├── Day27:Testing.java │ ├── Day6:Let'sReview.java │ ├── Day23:BSTLevel-OrderTraversal.java │ ├── Day3:IntrotoConditionalStatements.java │ ├── 30-arrays.cpp │ ├── Day11:2DArrays.java │ ├── Day29:BitwiseAND.java │ ├── Day4:Classvs.Instance.java │ ├── Day8:DictionariesandMaps.java │ ├── Day2:Operators.java │ ├── Day10:BinaryNumbers.java │ ├── Day12:Inheritance.java │ ├── Day25:RunningTimeandComplexity.java │ └── Day28:RegEx,Patterns,andIntrotoDatabases.java └── CrackingtheCodingInterview │ ├── Arrays:LeftRotation.java │ ├── LinkedLists:DetectaCycle.java │ ├── Recursion:FibonacciNumbers.java │ ├── Trees:IsThisaBinarySearchTree?.java │ ├── TimeComplexity:Primality.java │ ├── BitManipulation:LonelyInteger.java │ └── Strings:MakingAnagrams.java ├── Python ├── Introduction │ ├── write-a-function.py │ └── README.md └── README.md ├── Algorithms ├── GameTheory │ ├── PowersGame.java │ ├── AChessboardGame.java │ ├── TowerBreakers.java │ ├── README.md │ └── GameofStones.java ├── Recursion │ ├── README.md │ └── ThePowerSum.java ├── Warmup │ ├── SimpleArraySum.java │ ├── AVeryBigSum.java │ ├── SolveMeFirst.java │ ├── Staircase.java │ ├── BirthdayCakeCandles.java │ ├── TimeConversion.java │ ├── DiagonalDifference.java │ ├── Mini-MaxSum.java │ ├── PlusMinus.java │ └── ComparetheTriplets.java ├── Implementation │ ├── SherlockandSquares.java │ ├── ViralAdvertising.java │ ├── Kangaroo.java │ ├── DrawingBook.java │ ├── GradingStudents.java │ ├── StrangeCounter.java │ ├── ExtraLongFactorials.java │ ├── UtopianTree.java │ ├── HalloweenSale.java │ ├── CountingValleys.java │ ├── FindDigits.java │ ├── EqualizetheArray.java │ ├── ChocolateFeast.java │ ├── AngryProfessor.java │ ├── SavethePrisoner!.java │ ├── DayoftheProgrammer.java │ ├── JumpingontheClouds.java │ ├── BirthdayChocolate.java │ ├── ServiceLane.java │ ├── DivisibleSumPairs.java │ ├── BonAppétit.java │ ├── ElectronicsShop.java │ ├── MinimumDistances.java │ ├── CircularArrayRotation.java │ ├── BeautifulDaysattheMovies.java │ ├── TheHurdleRace.java │ ├── DesignerPDFViewer.java │ ├── JumpingontheClouds:Revisited.java │ ├── TaumandB'day.java │ ├── CatsandaMouse.java │ ├── SequenceEquation.java │ ├── Cutthesticks.java │ ├── SockMerchant.java │ ├── RepeatedString.java │ ├── LibraryFine.java │ ├── ManasaandStones.java │ ├── Lisa'sWorkbook.java │ ├── BreakingtheRecords.java │ ├── BeautifulTriplets.java │ ├── FairRations.java │ ├── 3DSurfaceArea.java │ └── ModifiedKaprekarNumbers.java ├── GraphTheory │ └── README.md ├── Sorting │ ├── IntrotoTutorialChallenges.java │ ├── FindtheMedian.java │ ├── CountingSort1.java │ ├── CountingSort2.java │ ├── ClosestNumbers.java │ ├── InsertionSort-Part1.java │ ├── Quicksort1-Partition.java │ ├── CorrectnessandtheLoopInvariant.java │ └── RunningTimeofAlgorithms.java ├── BitManipulation │ ├── Flippingbits.java │ ├── SumvsXOR.java │ ├── TheGreatXOR.java │ ├── ANDProduct.java │ ├── XoringNinja.java │ ├── Countergame.java │ └── MaximizingXOR.java ├── Strings │ ├── AlternatingCharacters.java │ ├── CamelCase.java │ ├── MarsExploration.java │ ├── FunnyString.java │ ├── StringConstruction.java │ ├── BeautifulBinaryString.java │ ├── SuperReducedString.java │ ├── StringFunctionCalculation.java │ ├── TheLove-LetterMystery.java │ ├── HackerRankinaString!.java │ ├── Pangrams.java │ ├── CaesarCipher.java │ └── GameofThrones-I.java ├── DynamicProgramming │ ├── FibonacciModified.java │ ├── Samandsubstrings.java │ └── TheMaximumSubarray.java ├── Search │ ├── Pairs.java │ ├── IceCreamParlor.java │ ├── AbsoluteElementSums.java │ ├── MaximumSubarraySum.java │ └── MissingNumbers.java ├── ConstructiveAlgorithms │ ├── README.md │ └── Beautiful3Set.java └── Greedy │ ├── MarkandToys.java │ ├── PriyankaandToys.java │ ├── ChiefHopper.java │ ├── MaximumPerimeterTriangle.java │ ├── Marc'sCakewalk.java │ ├── GreedyFlorist.java │ ├── SherlockandTheBeast.java │ ├── ReverseShuffleMerge.java │ └── LargestPermutation.java ├── ArtificialIntelligence ├── BotBuilding │ └── README.md └── README.md ├── DataStructures ├── Advanced │ └── README.md ├── Trees │ ├── Tree:HeightofaBinaryTree.java │ ├── Tree:InorderTraversal.java │ ├── Tree:PostorderTraversal.java │ ├── Tree:PreorderTraversal.java │ ├── Tree:TopView.java │ ├── Tree:LevelOrderTraversal.java │ ├── BinarySearchTree:LowestCommonAncestor.java │ ├── IsThisaBinarySearchTree?.java │ └── Tree:HuffmanDecoding.java ├── Arrays │ ├── Arrays-DS.java │ ├── SparseArrays.java │ ├── 2DArray-DS.java │ ├── LeftRotation.java │ ├── README.md │ └── ArrayManipulation.java ├── LinkedLists │ ├── PrintinReverse.java │ ├── PrinttheElementsofaLinkedList.java │ ├── Comparetwolinkedlists.java │ ├── CycleDetection.java │ ├── Mergetwosortedlinkedlists.java │ ├── Insertanodeattheheadofalinkedlist.java │ ├── InsertaNodeattheTailofaLinkedList.java │ ├── Deleteduplicate-valuenodesfromasortedlinkedlist.java │ ├── GetNodeValue.java │ ├── Reversealinkedlist.java │ ├── Reverseadoublylinkedlist.java │ ├── Insertanodeataspecificpositioninalinkedlist.java │ ├── DeleteaNode.java │ ├── InsertingaNodeIntoaSortedDoublyLinkedList.java │ └── FindMergePointofTwoLists.java └── Stacks │ ├── README.md │ └── LargestRectangle.java ├── Mathematics ├── Combinatorics │ ├── README.md │ └── SherlockandPairs.java └── Fundamentals │ ├── MaximumDraws.java │ ├── ArmyGame.java │ ├── FindthePoint.java │ ├── PossiblePath.java │ ├── DiwaliLights.java │ ├── SherlockandMovingTiles.java │ └── sherlock-and-permutations.cpp └── Others └── Miscellaneous ├── CountingSort3.java └── README.md /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /SQL/BasicSelect/select-all-sql.sql: -------------------------------------------------------------------------------- 1 | SELECT * FROM CITY -------------------------------------------------------------------------------- /Java/Introduction/JavaInttoString.java: -------------------------------------------------------------------------------- 1 | String s = n + ""; 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .idea/ 3 | .vscode/ 4 | .gradle/ 5 | *.class -------------------------------------------------------------------------------- /Databases/RelationalAlgebra/basics-of-sets-and-relational-algebra-1: -------------------------------------------------------------------------------- 1 | 8 -------------------------------------------------------------------------------- /Databases/RelationalAlgebra/basics-of-sets-and-relational-algebra-2: -------------------------------------------------------------------------------- 1 | 5 -------------------------------------------------------------------------------- /Databases/RelationalAlgebra/basics-of-sets-and-relational-algebra-3: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /Databases/RelationalAlgebra/basics-of-sets-and-relational-algebra-5: -------------------------------------------------------------------------------- 1 | 2 -------------------------------------------------------------------------------- /Databases/RelationalAlgebra/basics-of-sets-and-relational-algebra-6: -------------------------------------------------------------------------------- 1 | 2 -------------------------------------------------------------------------------- /Databases/RelationalAlgebra/basics-of-sets-and-relational-algebra-7: -------------------------------------------------------------------------------- 1 | 2 -------------------------------------------------------------------------------- /LinuxShell/Bash/bash-tutorials-lets-echo.sh: -------------------------------------------------------------------------------- 1 | echo "HELLO" 2 | 3 | -------------------------------------------------------------------------------- /SQL/BasicSelect/select-by-id.sql: -------------------------------------------------------------------------------- 1 | SELECT * FROM CITY WHERE ID = 1661 -------------------------------------------------------------------------------- /Databases/RelationalAlgebra/basics-of-sets-and-relational-algebra-4: -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /SQL/BasicSelect/weather-observation-station-1.sql: -------------------------------------------------------------------------------- 1 | SELECT CITY,STATE FROM STATION -------------------------------------------------------------------------------- /SQL/BasicSelect/japanese-cities-name.sql: -------------------------------------------------------------------------------- 1 | SELECT NAME FROM CITY WHERE COUNTRYCODE = 'JPN' -------------------------------------------------------------------------------- /SQL/BasicSelect/japanese-cities-attributes.sql: -------------------------------------------------------------------------------- 1 | SELECT * FROM CITY WHERE COUNTRYCODE = 'JPN' -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | patreon: rajatgoyal 4 | -------------------------------------------------------------------------------- /LinuxShell/Bash/bash-tutorials---a-personalized-echo.sh: -------------------------------------------------------------------------------- 1 | read name 2 | echo "Welcome $name" 3 | -------------------------------------------------------------------------------- /Java/Strings/ValidUsernameRegularExpression.java: -------------------------------------------------------------------------------- 1 | String pattern = "^[A-Za-z][A-Za-z0-9_]{7,29}$"; 2 | -------------------------------------------------------------------------------- /SQL/BasicSelect/weather-observation-station-3.sql: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT CITY FROM STATION WHERE (ID % 2) = 0 -------------------------------------------------------------------------------- /SQL/BasicSelect/revising-the-select-query.sql: -------------------------------------------------------------------------------- 1 | SELECT * FROM CITY WHERE POPULATION>100000 AND COUNTRYCODE = 'USA' -------------------------------------------------------------------------------- /SQL/BasicSelect/revising-the-select-query-2.sql: -------------------------------------------------------------------------------- 1 | SELECT NAME FROM CITY WHERE POPULATION > 120000 AND COUNTRYCODE = 'USA' -------------------------------------------------------------------------------- /LinuxShell/Bash/bash-tutorials---looping-and-skipping.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | x=1 3 | while [ $x -le 99 ] 4 | do 5 | echo $x 6 | x=$((x+2)) 7 | done 8 | -------------------------------------------------------------------------------- /LinuxShell/Bash/bash-tutorials---looping-with-numbers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | x=1 3 | while [ $x -le 50 ] 4 | do 5 | echo $x 6 | x=$((x+1)) 7 | done 8 | 9 | -------------------------------------------------------------------------------- /Regex/Backreferences/branch-reset-groups.php: -------------------------------------------------------------------------------- 1 | $Regex_Pattern = '/^\d\d(-|:|---|.)\d\d\1\d\d\1\d\d$/'; //Do not delete '/'. Replace __________ with your regex. 2 | -------------------------------------------------------------------------------- /LinuxShell/Bash/bash-tutorials---the-world-of-numbers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read x 3 | read y 4 | echo $(($x+$y)) 5 | echo $(($x-$y)) 6 | echo $(($x*$y)) 7 | echo $(($x/$y)) 8 | -------------------------------------------------------------------------------- /Security/Functions/SecurityFunctions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Complete the function below. 3 | */ 4 | 5 | static int function(int x) { 6 | return x%11; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Security/Functions/SecurityFunctionsII.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Complete the function below. 3 | */ 4 | 5 | static int function(int x) { 6 | return x*x; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Java/ObjectOrientedProgramming/JavaMethodOverriding.java: -------------------------------------------------------------------------------- 1 | void getNumberOfTeamMembers(){ 2 | System.out.println( "Each team has "+11+" players in " + getName() ); 3 | } -------------------------------------------------------------------------------- /Java/ObjectOrientedProgramming/JavaInheritanceII.java: -------------------------------------------------------------------------------- 1 | class Arithmetic{ 2 | public int add(int a,int b){ 3 | return a+b; 4 | } 5 | } 6 | class Adder extends Arithmetic{ 7 | 8 | } -------------------------------------------------------------------------------- /Java/DataStructures/JavaGenerics.java: -------------------------------------------------------------------------------- 1 | class Printer 2 | { 3 | public static void printArray(T[] a){ 4 | for(int i=0;i{ 2 | public int compare(Player a, Player b){ 3 | if(a.score==b.score) 4 | return a.name.compareTo(b.name); 5 | else 6 | return b.score-a.score; 7 | } 8 | } -------------------------------------------------------------------------------- /Java/ExceptionHandling/JavaExceptionHandling.java: -------------------------------------------------------------------------------- 1 | class myCalculator { 2 | int power(int n,int p) throws Exception{ 3 | if(n<0||p<0){ 4 | throw new Exception("n and p should be non-negative"); 5 | } 6 | return (int)Math.pow(n,p); 7 | } 8 | } -------------------------------------------------------------------------------- /Regex/Assertions/PositiveLookbehind.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | 5 | Regex_Test tester = new Regex_Test(); 6 | tester.checker("(?<=[13579])(\\d)"); //Use '\\' instead of '\'. 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /Regex/Repetitions/MatchingEndingItems.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | 5 | Regex_Test tester = new Regex_Test(); 6 | tester.checker("^[a-zA-Z]*s+$"); // Use \\ instead of using \ 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /LinuxShell/Bash/bash-tutorials---getting-started-with-conditionals.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read choice 3 | 4 | if [ "$choice" == "Y" ] || [ "$choice" == "y" ]; then 5 | echo "YES" 6 | fi 7 | 8 | if [ "$choice" == "N" ] || [ "$choice" == "n" ]; then 9 | echo "NO" 10 | fi 11 | -------------------------------------------------------------------------------- /Regex/Backreferences/ForwardReferences.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | 5 | Regex_Test tester = new Regex_Test(); 6 | tester.checker("^(\\2tic|(tac))+$"); // Use \\ instead of using \ 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /Regex/Introduction/MatchingStart&End.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | 5 | Regex_Test tester = new Regex_Test(); 6 | tester.checker("^\\d\\w\\w\\w\\w\\.$"); // Use \\ instead of using \ 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /Regex/Assertions/NegativeLookbehind.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | 5 | Regex_Test tester = new Regex_Test(); 6 | tester.checker("(?0 && B>0); 5 | static{ 6 | if(!flag){ 7 | System.out.print("java.lang.Exception: Breadth and height must be positive"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LinuxShell/Bash/bash-tutorials---comparing-numbers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read x 3 | read y 4 | 5 | if (( $x < $y )); then 6 | echo "X is less than Y" 7 | fi 8 | 9 | if (( $x > $y )); then 10 | echo "X is greater than Y" 11 | fi 12 | 13 | if [ $x -eq $y ]; then 14 | echo "X is equal to Y" 15 | fi 16 | 17 | 18 | -------------------------------------------------------------------------------- /Mathematics/Combinatorics/README.md: -------------------------------------------------------------------------------- 1 | ## [Combinatorics](https://www.hackerrank.com/domains/mathematics/combinatorics) 2 | 3 | |Problem Name|Problem Link|Language|Solution Link| 4 | ---|---|---|--- 5 | |Sherlock and Pairs|[Problem](https://www.hackerrank.com/challenges/sherlock-and-pairs/problem)|java8|[Solution](./SherlockandPairs.java)| 6 | -------------------------------------------------------------------------------- /Regex/Introduction/MatchingWord&Non-WordCharacter.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | 5 | Regex_Test tester = new Regex_Test(); 6 | tester.checker("\\w\\w\\w\\W\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w\\W\\w\\w\\w"); // Use \\ instead of using \ 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /DataStructures/Trees/Tree:HeightofaBinaryTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | class Node 4 | int data; 5 | Node left; 6 | Node right; 7 | */ 8 | int height(Node root) 9 | { 10 | if(root==null) 11 | return -1; 12 | return Math.max(height(root.left),height(root.right))+1; 13 | } 14 | -------------------------------------------------------------------------------- /ArtificialIntelligence/README.md: -------------------------------------------------------------------------------- 1 | ## [ArtificialIntelligence](https://www.hackerrank.com/domains/ai) 2 | 3 | |Subdomain|Problem Name|Problem Link|Language|Solution Link| 4 | ---|---|---|---|--- 5 | |BotBuilding|Bot saves princess|[Problem](https://www.hackerrank.com/challenges/saveprincess/problem)|java|[Solution](BotBuilding/Botsavesprincess.java)| 6 | -------------------------------------------------------------------------------- /Java/Advanced/JavaVarargs-SimpleAddition.java: -------------------------------------------------------------------------------- 1 | class Add{ 2 | public static void add(int ... num){ 3 | int l = num.length; 4 | int sum=num[0]; 5 | String s=num[0]+""; 6 | for(int i=1;imax) 11 | max=elements[i]; 12 | if(elements[i] queue = new Queue(); 4 | LinkedList ll = new LinkedList(); 5 | void pushCharacter(char ch){ 6 | stack.push(ch); 7 | } 8 | char popCharacter(){ 9 | return (char)stack.pop(); 10 | } 11 | void enqueueCharacter(char ch){ 12 | ll.add(ch); 13 | } 14 | char dequeueCharacter(){ 15 | return (char)ll.remove(); 16 | } -------------------------------------------------------------------------------- /Algorithms/GameTheory/AChessboardGame.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int t = sc.nextInt(); 12 | while(t--!=0){ 13 | int x = sc.nextInt(); 14 | int y = sc.nextInt(); 15 | System.out.println(((((x-1)/2)%2 != 0) || (((y-1)/2)%2 != 0)) ? "First" : "Second"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Java/Advanced/JavaSingletonPattern.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.*; 3 | import java.util.*; 4 | import java.text.*; 5 | import java.math.*; 6 | import java.util.regex.*; 7 | import java.lang.reflect.*; 8 | 9 | 10 | class Singleton{ 11 | public String str; 12 | private static Singleton instance = null; 13 | private Singleton(){ 14 | 15 | } 16 | public static Singleton getSingleInstance(){ 17 | if(instance==null) instance = new Singleton(); 18 | return instance; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Mathematics/Fundamentals/FindthePoint.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc=new Scanner(System.in); 8 | int t=sc.nextInt(); 9 | while(t--!=0){ 10 | int px=sc.nextInt(); 11 | int py=sc.nextInt(); 12 | int qx=sc.nextInt(); 13 | int qy=sc.nextInt(); 14 | System.out.println((2*qx-px) + " " + (2*qy-py)); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Algorithms/GameTheory/TowerBreakers.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc=new Scanner(System.in); 11 | int t=sc.nextInt(); 12 | while(t--!=0){ 13 | int n=sc.nextInt(); 14 | int m=sc.nextInt(); 15 | System.out.println((m == 1 || n % 2 == 0) ? 2 : 1); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Algorithms/Implementation/ViralAdvertising.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc=new Scanner(System.in); 11 | int n=sc.nextInt(); 12 | int a=5,c=0; 13 | for(int i=0;i(); 11 | q.add(root); 12 | while(!q.isEmpty()){ 13 | Node t=(Node)q.remove(); 14 | System.out.print(t.data+" "); 15 | if(t.left!=null) 16 | q.add(t.left); 17 | if(t.right!=null) 18 | q.add(t.right); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Algorithms/BitManipulation/SumvsXOR.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | long n = in.nextLong(); 12 | long count=0; 13 | while(n!=0) { 14 | if(n%2==0) 15 | count++; 16 | n/=2; 17 | } 18 | System.out.println((long)Math.pow(2,count)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Java/Introduction/JavaIf-Else.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc=new Scanner(System.in); 8 | int n=sc.nextInt(); 9 | String ans=""; 10 | if(n%2==1)ans = "Weird"; 11 | else 12 | { 13 | if(n>=2 && n<=5)ans = "Not Weird"; 14 | if(n>=6 && n<=20)ans = "Weird"; 15 | if(n>20)ans = "Not Weird"; 16 | 17 | } 18 | System.out.println(ans); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Algorithms/Implementation/Kangaroo.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | int x1 = in.nextInt(); 12 | int v1 = in.nextInt(); 13 | int x2 = in.nextInt(); 14 | int v2 = in.nextInt(); 15 | float t=((float)(x2-x1))/((float)(v1-v2)); 16 | System.out.println((t%1==0&&t>=0)?"YES":"NO"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Java/BigNumber/README.md: -------------------------------------------------------------------------------- 1 | ## [BigNumber](https://www.hackerrank.com/domains/java/bignumber) 2 | 3 | |Problem Name|Problem Link|Language|Solution Link| 4 | ---|---|---|--- 5 | |Java BigDecimal|[Problem](https://www.hackerrank.com/challenges/java-bigdecimal/problem)|java8|[Solution](./JavaBigDecimal.java)| 6 | |Java BigInteger|[Problem](https://www.hackerrank.com/challenges/java-biginteger/problem)|java|[Solution](./JavaBigInteger.java)| 7 | |Java Primality Test|[Problem](https://www.hackerrank.com/challenges/java-primality-test/problem)|java|[Solution](./JavaPrimalityTest.java)| 8 | -------------------------------------------------------------------------------- /Algorithms/Implementation/DrawingBook.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | int n = in.nextInt(); 12 | int p = in.nextInt(); 13 | 14 | int total = n/2 + 1; 15 | int start = p/2; 16 | int end = total - start - 1; 17 | 18 | System.out.println(Math.min(start, end)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Algorithms/Implementation/GradingStudents.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | int n = in.nextInt(); 12 | for(int a0 = 0; a0 < n; a0++){ 13 | int grade = in.nextInt(); 14 | grade = (grade>=38 && grade%5>=3)?(5*(grade/5+1)):grade; 15 | System.out.println(grade); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Algorithms/Implementation/StrangeCounter.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | long t = in.nextLong(); 12 | long a=3; 13 | long b=1; 14 | long c=3; 15 | while(t>c){ 16 | b=c+1; 17 | a*=2; 18 | c+=a; 19 | } 20 | System.out.println((a+b)-t); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Java/DataStructures/JavaHashset.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Set s = new HashSet(); 11 | Scanner sc=new Scanner(System.in); 12 | int t=sc.nextInt(); 13 | sc.nextLine(); 14 | while(t-->0){ 15 | String str=sc.nextLine(); 16 | s.add(str); 17 | System.out.println(s.size()); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Tutorials/30DaysofCode/Day16:Exceptions-StringtoInteger.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | String S = in.next(); 12 | try{ 13 | int num = Integer.parseInt(S); 14 | System.out.println(num); 15 | }catch(Exception e){ 16 | System.out.println("Bad String"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Algorithms/Implementation/ExtraLongFactorials.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.math.BigInteger; 3 | public class Solution { 4 | 5 | public static BigInteger factorial(int num){ 6 | BigInteger fact = BigInteger.ONE; 7 | for(int i=num;i>1;i--){ 8 | fact = fact.multiply(BigInteger.valueOf(i)); 9 | } 10 | return fact; 11 | } 12 | public static void main(String[] args) { 13 | Scanner s = new Scanner(System.in); 14 | int n = s.nextInt(); 15 | System.out.println(factorial(n)); 16 | } 17 | } -------------------------------------------------------------------------------- /DataStructures/LinkedLists/Comparetwolinkedlists.java: -------------------------------------------------------------------------------- 1 | /* 2 | Compare two linked lists A and B 3 | Return 1 if they are identical and 0 if they are not. 4 | Node is defined as 5 | class Node { 6 | int data; 7 | Node next; 8 | } 9 | */ 10 | int CompareLists(Node headA, Node headB) { 11 | int isequal = 1; 12 | while(headA!=null && headB!=null){ 13 | if(headA.data!=headB.data) 14 | isequal = 0; 15 | headA = headA.next; 16 | headB = headB.next; 17 | } 18 | return (headA==null&&headB==null)?isequal:0; 19 | } 20 | -------------------------------------------------------------------------------- /Algorithms/Strings/AlternatingCharacters.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | public static void main(String args[]){ 5 | Scanner sc = new Scanner(System.in); 6 | int t = sc.nextInt(); 7 | while((t--)!=0){ 8 | int delete = 0; 9 | String s = sc.next(); 10 | int l = s.length(); 11 | for(int i=1;i=65) 17 | c++; 18 | } 19 | System.out.println(c); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Tutorials/CrackingtheCodingInterview/Arrays:LeftRotation.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String args[]) { 10 | Scanner sc=new Scanner(System.in); 11 | int n=sc.nextInt(); 12 | int d=sc.nextInt(); 13 | int a[]=new int[n]; 14 | for(int i=0;i map = new HashMap(); 12 | for(int i=1;i<=n;i++){ 13 | map.put(i,sc.nextInt()); 14 | } 15 | for(int i=1;i<=n;i++){ 16 | System.out.println(map.get(map.get(i))); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Java/Strings/JavaStringReverse.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc=new Scanner(System.in); 9 | String A=sc.next(); 10 | int l = A.length(); 11 | boolean ispallin = true; 12 | for(int i=0;i map = new HashMap(); 13 | for(int i=1;i<=n;i++){ 14 | map.put(sc.nextInt(),i); 15 | } 16 | for(int i=1;i<=n;i++){ 17 | System.out.println(map.get(i)); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Security/TerminologyandConcepts/Security-MessageSpaceandCiphertextSpace.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | public static void main(String[] args) { 9 | Scanner sc=new Scanner(System.in); 10 | String s=sc.nextLine(); 11 | String ans=""; 12 | int num; 13 | for(int i=0;i= 0){ 16 | if(p > m){ 17 | s -= p; 18 | p -= d; 19 | } else{ 20 | s -= m; 21 | } 22 | count++; 23 | } 24 | System.out.println(count-1); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Java/Introduction/JavaLoopsII.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int t = sc.nextInt(); 8 | while(t!=0){ 9 | int a = sc.nextInt(); 10 | int b = sc.nextInt(); 11 | int n = sc.nextInt(); 12 | for(int i=0;i max) { 17 | max = h[i]; 18 | count = 0; 19 | } 20 | if(h[i] == max) { 21 | count++; 22 | } 23 | } 24 | System.out.println(count); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Java/Advanced/JavaReflection-Attributes.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) throws Exception{ 4 | Class student = Class.forName("Student"); 5 | Method[] methods = student.getDeclaredMethods(); 6 | 7 | ArrayList methodList = new ArrayList<>(); 8 | for(Method method:methods){ 9 | methodList.add(method.getName()); 10 | } 11 | Collections.sort(methodList); 12 | for(String name: methodList){ 13 | System.out.println(name); 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /DataStructures/LinkedLists/Mergetwosortedlinkedlists.java: -------------------------------------------------------------------------------- 1 | /* 2 | Merge two linked lists 3 | head pointer input could be NULL as well for empty list 4 | Node is defined as 5 | class Node { 6 | int data; 7 | Node next; 8 | } 9 | */ 10 | 11 | Node MergeLists(Node headA, Node headB) { 12 | if(headA==null) 13 | return headB; 14 | if(headB==null) 15 | return headA; 16 | if(headA.data(); 5 | Node temp=head; 6 | a.add(temp.data); 7 | while(temp.next!=null){ 8 | Node temp2 = temp.next; 9 | int t=temp2.data; 10 | if(!a.contains(t)){ 11 | a.add(t); 12 | temp=temp.next; 13 | } 14 | else{ 15 | temp.next = temp.next.next; 16 | } 17 | } 18 | return head; 19 | } -------------------------------------------------------------------------------- /Algorithms/Implementation/FindDigits.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | Scanner s = new Scanner(System.in); 7 | int t = s.nextInt(); 8 | while(t!=0){ 9 | int num = s.nextInt(); 10 | int n = num; 11 | int count=0; 12 | while(n!=0){ 13 | if(n%10!=0){ 14 | if(num%(n%10)==0) 15 | count++; 16 | } 17 | n = n/10; 18 | } 19 | System.out.println(count); 20 | t--; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /DataStructures/LinkedLists/InsertaNodeattheTailofaLinkedList.java: -------------------------------------------------------------------------------- 1 | /* 2 | Insert Node at the end of a linked list 3 | head pointer input could be NULL as well for empty list 4 | Node is defined as 5 | class Node { 6 | int data; 7 | Node next; 8 | } 9 | */ 10 | Node Insert(Node head,int data) { 11 | Node temp = new Node(); 12 | Node ptr = new Node(); 13 | temp = head; 14 | ptr.data = data; 15 | ptr.next = null; 16 | if(head==null){ 17 | head = ptr; 18 | } 19 | else{ 20 | while(temp.next!=null) 21 | temp = temp.next; 22 | temp.next = ptr; 23 | } 24 | return head; 25 | } 26 | -------------------------------------------------------------------------------- /DataStructures/Trees/BinarySearchTree:LowestCommonAncestor.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* Node is defined as : 4 | class Node 5 | int data; 6 | Node left; 7 | Node right; 8 | 9 | */ 10 | 11 | static Node lca(Node root,int v1,int v2) 12 | { 13 | Node temp = root; 14 | while(temp!=null){ 15 | if(temp.data == v1 || temp.data == v2 || (temp.data > v1 && temp.data < v2) || (temp.data > v2 && temp.data < v1)) return temp; 16 | else if(temp.data > v1 && temp.data > v2) temp = temp.left; 17 | else temp = temp.right; 18 | } 19 | return temp; 20 | } 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Security/Functions/SecurityBijectiveFunctions.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc=new Scanner(System.in); 11 | int n=sc.nextInt(); 12 | BitSet b = new BitSet(); 13 | String ans="YES"; 14 | int num; 15 | 16 | while(n--!=0){ 17 | num=sc.nextInt(); 18 | if(b.get(num)) 19 | ans="NO"; 20 | b.set(num); 21 | } 22 | System.out.println(ans); 23 | } 24 | } -------------------------------------------------------------------------------- /DataStructures/LinkedLists/Deleteduplicate-valuenodesfromasortedlinkedlist.java: -------------------------------------------------------------------------------- 1 | /* 2 | Node is defined as 3 | class Node { 4 | int data; 5 | Node next; 6 | } 7 | */ 8 | 9 | Node RemoveDuplicates(Node head) { 10 | Node start=head; 11 | Node second=start.next; 12 | int temp=start.data; 13 | while(start!=null){ 14 | second = start.next; 15 | temp=start.data; 16 | while(second!=null&&second.data==temp){ 17 | second = second.next; 18 | } 19 | start.next = second; 20 | start = start.next; 21 | } 22 | return head; 23 | } 24 | -------------------------------------------------------------------------------- /Algorithms/Sorting/CountingSort2.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int N = sc.nextInt(); 12 | int c[] = new int[100]; 13 | for(int i=0;i0){ 11 | String pattern = in.nextLine(); 12 | try{ 13 | Pattern.compile(pattern); 14 | System.out.println("Valid"); 15 | } 16 | catch(Exception e){ 17 | System.out.println("Invalid"); 18 | } 19 | testCases--; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Algorithms/Implementation/EqualizetheArray.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc=new Scanner(System.in); 11 | int n=sc.nextInt(); 12 | int a[]=new int[n]; 13 | int b[]=new int[101]; 14 | int max=0; 15 | for(int i=0;i0){ 10 | int n=sc.nextInt(); 11 | int b[]=new int[1000000]; 12 | for(int i=0;i=M){ 18 | c = c + w/M; 19 | w = w/M + w%M; 20 | } 21 | return c; 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Java/Introduction/JavaStdinandStdoutII.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.io.IOException; 4 | 5 | public class Solution { 6 | 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader x = new BufferedReader(new InputStreamReader(System.in)); 9 | int a = Integer.parseInt(x.readLine()); 10 | Double y = Double.parseDouble(x.readLine()); 11 | String s = x.readLine(); 12 | 13 | System.out.println("String: " + s); 14 | System.out.println("Double: " + y); 15 | System.out.println("Int: " + a); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Others/Miscellaneous/CountingSort3.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int N = sc.nextInt(); 12 | int c[] = new int[100]; 13 | for(int i=0;i0) 13 | System.out.println("Yes"); 14 | else 15 | System.out.println("No"); 16 | System.out.println(Character.toUpperCase(A.charAt(0)) + A.substring(1) + 17 | " " + Character.toUpperCase(B.charAt(0)) + B.substring(1)); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Regex/CharacterClass/README.md: -------------------------------------------------------------------------------- 1 | ## [CharacterClass](https://www.hackerrank.com/domains/regex/re-character-class) 2 | 3 | |Problem Name|Problem Link|Language|Solution Link| 4 | ---|---|---|--- 5 | |Excluding Specific Characters|[Problem](https://www.hackerrank.com/challenges/excluding-specific-characters/problem)|java8|[Solution](./ExcludingSpecificCharacters.java)| 6 | |Matching Character Ranges|[Problem](https://www.hackerrank.com/challenges/matching-range-of-characters/problem)|java8|[Solution](./MatchingCharacterRanges.java)| 7 | |Matching Specific Characters|[Problem](https://www.hackerrank.com/challenges/matching-specific-characters/problem)|java8|[Solution](./MatchingSpecificCharacters.java)| 8 | -------------------------------------------------------------------------------- /Security/Functions/SecurityInvolution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | public static void main(String[] args) { 9 | Scanner sc=new Scanner(System.in); 10 | int n=sc.nextInt(); 11 | Map map = new HashMap(); 12 | for(int i=1;i<=n;i++){ 13 | map.put(i,sc.nextInt()); 14 | } 15 | String ans="YES"; 16 | for(int i=1;i<=n;i++){ 17 | if(map.get(map.get(i))!=i) 18 | ans="NO"; 19 | } 20 | System.out.println(ans); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/BigNumber/JavaBigDecimal.java: -------------------------------------------------------------------------------- 1 | import java.math.BigDecimal; 2 | import java.util.*; 3 | class Solution{ 4 | public static void main(String []argh) 5 | { 6 | Scanner sc= new Scanner(System.in); 7 | int n=sc.nextInt(); 8 | String []s=new String[n]; 9 | 10 | // input 11 | for(int i=0;i {BigDecimal bd1 = new BigDecimal(bs); 16 | return bd1.compareTo(new BigDecimal(as));} ); 17 | 18 | // output 19 | for(int i=0;i25) 12 | n-=32; 13 | s1[n]++; 14 | n=b.charAt(i)-65; 15 | if(n>25) 16 | n-=32; 17 | s2[n]++; 18 | } 19 | for(int i=0;i<26;i++){ 20 | if(s1[i]!=s2[i]) 21 | return false; 22 | } 23 | return true; 24 | } -------------------------------------------------------------------------------- /Tutorials/30DaysofCode/Day0:Hello,World..java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | public static void main(String[] args) { 9 | Scanner scan = new Scanner(System.in); // use the Scanner class to read from stdin 10 | String inputString = scan.nextLine(); // read a line of input and save it to a variable 11 | scan.close(); // close the scanner 12 | 13 | // Your first line of output goes here 14 | System.out.println("Hello, World."); 15 | System.out.println(inputString); 16 | 17 | // Write the second line of output 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Algorithms/Implementation/AngryProfessor.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int t = sc.nextInt(); 8 | while(t!=0){ 9 | int count=0; 10 | int n = sc.nextInt(); 11 | int k = sc.nextInt(); 12 | while(n!=0){ 13 | if(sc.nextInt()<=0) 14 | count++; 15 | n--; 16 | } 17 | if(count>=k) 18 | System.out.println("NO"); 19 | else 20 | System.out.println("YES"); 21 | t--; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Algorithms/Implementation/SavethePrisoner!.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc=new Scanner(System.in); 11 | int t=sc.nextInt(); 12 | while(t-->0){ 13 | int n=sc.nextInt(); 14 | int m=sc.nextInt(); 15 | int s=sc.nextInt()-1; 16 | while(m-->0){ 17 | s++; 18 | if(s>n) 19 | s=s%n; 20 | } 21 | //int a=(s+m-1)%5; 22 | System.out.println(s); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Java/Advanced/PrimeChecker.java: -------------------------------------------------------------------------------- 1 | import static java.lang.System.*; 2 | class Prime{ 3 | public static void checkPrime(int ... num){ 4 | int l = num.length; 5 | for(int i:num){ 6 | if(prime(i)) 7 | System.out.print(i+" "); 8 | } 9 | System.out.println(); 10 | } 11 | public static boolean prime(int num){ 12 | if(num==1) 13 | return false; 14 | if(num==2||num==3) 15 | return true; 16 | if(num%2==0) 17 | return false; 18 | for(int i=3;i<=Math.sqrt(num);i+=2){ 19 | if(num%i==0) 20 | return false; 21 | } 22 | return true; 23 | } 24 | } -------------------------------------------------------------------------------- /Java/Introduction/JavaDateandTime.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | import java.time.LocalDate; 7 | 8 | public class Solution { 9 | 10 | public static void main(String[] args) { 11 | Scanner in = new Scanner(System.in); 12 | //String month = in.next(); 13 | int mm = in.nextInt(); 14 | //String day = in.next(); 15 | int dd = in.nextInt(); 16 | //String year = in.next(); 17 | int yy = in.nextInt(); 18 | in.close(); 19 | LocalDate dt = LocalDate.of(yy, mm, dd); 20 | System.out.print(dt.getDayOfWeek()); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Security/TerminologyandConcepts/README.md: -------------------------------------------------------------------------------- 1 | ## [TerminologyandConcepts](https://www.hackerrank.com/domains/security/concepts) 2 | 3 | |Problem Name|Problem Link|Language|Solution Link| 4 | ---|---|---|--- 5 | |Security - Message Space and Ciphertext Space|[Problem](https://www.hackerrank.com/challenges/security-message-space-and-ciphertext-space/problem)|java|[Solution](./Security-MessageSpaceandCiphertextSpace.java)| 6 | |Security Encryption Scheme|[Problem](https://www.hackerrank.com/challenges/security-encryption-scheme/problem)|java|[Solution](./SecurityEncryptionScheme.java)| 7 | |Security Key Spaces|[Problem](https://www.hackerrank.com/challenges/security-key-spaces/problem)|java|[Solution](./SecurityKeySpaces.java)| 8 | -------------------------------------------------------------------------------- /Tutorials/30DaysofCode/Day1:DataTypes.java: -------------------------------------------------------------------------------- 1 | /* Declare second integer, double, and String variables. */ 2 | int num=scan.nextInt(); 3 | System.out.println(num+i); 4 | /* Read and save an integer, double, and String to your variables.*/ 5 | Double n=scan.nextDouble(); 6 | System.out.println(n+d); 7 | /* Print the sum of both integer variables on a new line. */ 8 | String st=scan.nextLine(); 9 | st=scan.nextLine(); 10 | //System.out.println(st); 11 | System.out.println(s+st); 12 | /* Print the sum of the double variables on a new line. */ 13 | 14 | /* Concatenate and print the String variables on a new line; 15 | the 's' variable above should be printed first. */ 16 | -------------------------------------------------------------------------------- /Algorithms/Implementation/DayoftheProgrammer.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | static String day, month; 10 | 11 | public static void main(String[] args) { 12 | Scanner in = new Scanner(System.in); 13 | int y = in.nextInt(); 14 | 15 | if((y>1919 && (y%400==0 || (y%4==0&&y%100!=0))) || (y<1918 && y%4==0)) { 16 | System.out.println("12.09." + y); 17 | } else if(y==1918){ 18 | System.out.println("26.09.1918"); 19 | } else { 20 | System.out.println("13.09." + y); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DataStructures/LinkedLists/GetNodeValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | Insert Node at the end of a linked list 3 | head pointer input could be NULL as well for empty list 4 | Node is defined as 5 | class Node { 6 | int data; 7 | Node next; 8 | } 9 | */ 10 | 11 | int GetNode(Node head,int n) { 12 | // This is a "method-only" submission. 13 | // You only need to complete this method. 14 | Node temp = new Node(); 15 | temp = head; 16 | int t = 1; 17 | while(temp.next!=null){ 18 | temp = temp.next; 19 | t++; 20 | } 21 | int num = t-n; 22 | temp = head; 23 | for(int i=1;itemp+4){ 21 | cost++; 22 | temp = a[i]; 23 | } 24 | } 25 | System.out.println(cost); 26 | } 27 | } -------------------------------------------------------------------------------- /Algorithms/Strings/FunnyString.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | public static void main(String args[]){ 5 | Scanner sc = new Scanner(System.in); 6 | int t = sc.nextInt(); 7 | while(t--!=0){ 8 | boolean isfunny = true; 9 | String s = sc.next(); 10 | int l = s.length(); 11 | for(int i=1;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | long long nchoosek(int n, int k){ 9 | 10 | if(n>t; 27 | while(t--){ 28 | int n,k; 29 | cin>>n>>k; 30 | long long t = nchoosek(n+k-1,k-1); 31 | cout<