├── ProblemSolving (General) ├── Temp - Copy (9).py ├── README.md ├── CorrectnessAndTheLoopInvariant.java ├── XORStrings.java ├── Staircase.java ├── SmartNumber.java ├── MiniMaxSum.java ├── DrawingBook.java ├── FlippingBits.java ├── ViralAdvertising.java ├── Pangrams.java ├── TimeConversion.java ├── SaveThePrisoner.java ├── CamelCase.java ├── FindDigits.java ├── CatsAndAMouse.java ├── BeautifulDaysAtTheMovies.java ├── SherlockAndSquares.java ├── AVeryBigSum.java ├── BeautifulBinaryString.java ├── FunnyString.java ├── PlusMinus.java ├── SuperReducedString.java ├── TwoStrings.java ├── FindTheMedian.java ├── ChocolateFeast.java ├── BillDivision.java ├── SumvsXOR.java ├── CommonChild.java ├── TheHurdleRace.java ├── PriyankaAndToys.java ├── RepeatedString.java ├── HalloweenSale.java ├── CaesarCipher.java ├── GameOfThronesI.java ├── MaxMin.java ├── MarcsCakewalk.java ├── BirthdayCakeCandles.java ├── SalesByMatch.java ├── DivisibleSumPairs.java ├── HackerRankInAString.java ├── MinimumAbsoluteDifferenceInAnArray.java ├── JumpingOnTheClouds.java ├── LonelyInteger.java ├── MinimumDistances.java ├── DesignerPDFViewer.java ├── PalindromeIndex.java ├── SherlockAndTheValidString.java ├── MigratoryBirds.java ├── AngryProfessor.java ├── Encryption.java ├── SubarrayDivision.java ├── GridChallenge.java ├── CountingValleys.java ├── SherlockAndAnagrams.java ├── CompareTheTriplets.java ├── BreakingTheRecords.java ├── ModifiedKaprekarNumbers.java ├── SequenceEquation.java ├── TimeInWords.java ├── ClosestNumbers.java ├── FairRations.java ├── SherlockAndArray.java ├── DiagonalDifference.java ├── CircularArrayRotation.java ├── IceCreamParlor.java ├── EqualizeTheArray.java ├── ACMICPCTeam.java ├── AppleAndOrange.java ├── FlatlandSpaceStations.java ├── StrongPassword.java ├── GradingStudents.java ├── CutTheSticks.java ├── ServiceLane.java ├── LuckBalance.java ├── WeightedUniformStrings.java ├── PermutingTwoArrays.java ├── ElectronicsShop.java ├── JimAndTheOrders.java ├── BetweenTwoSets.java └── MissingNumbers.java ├── PythonSolutions ├── ReSplit.py ├── SayHelloWorldWithPython.py ├── sWAPcASE.py ├── PythonEvaluation.py ├── WhatIsYourName.py ├── ShapeAndReshape.py ├── Polynomials.py ├── PythonDivision.py ├── Loops.py ├── EyeAndIdentity.py ├── Mutations.py ├── PrintFunction.py ├── StringSplitAndJoin.py ├── Tuples.py ├── ZerosAndOnes.py ├── Arithmetic Operators.py ├── SetAdd.py ├── AnyOrAll.py ├── PowerModPower.py ├── FindAngleMBC.py ├── IntegersComeInAllSizes.py ├── Capitalize.py ├── CollectionsNamedTuple.py ├── TextWrap.py ├── Arrays.py ├── ItertoolsProduct.py ├── SetUnionOperation.py ├── InnerAndOuter.py ├── SetDifferenceOperation.py ├── SetIntersectionOperation.py ├── WriteAFunction.py ├── FloorCeilAndRint.py ├── LinearAlgebra.py ├── NoIdea.py ├── IncorrectRegex.py ├── SetSymmetricDifference.py ├── CalendarModule.py ├── FindAString.py ├── ItertoolsPermutations.py ├── CollectionsCounter.py ├── ValidatingPhoneNumbers.py ├── FindTheRunnerUpScore.py ├── ItertoolsCombinationsWithReplacement.py ├── PythonIfElse.py ├── MinAndMax.py ├── SumAndProd.py ├── TransposeAndFlatten.py ├── CheckStrictSuperset.py ├── CheckSubset.py ├── DotAndCross.py ├── ItertoolsCombinations.py ├── Zipped.py ├── CollectionsOrderedDict.py ├── FindingThePercentage.py ├── SetDiscardRemovePop.py ├── Concatenate.py ├── MeanVarAndStd.py ├── TheMinionGame.py ├── SymmetricDifference.py ├── TheCaptainsRoom.py ├── SetMutations.py ├── StringValidators.py ├── CollectionsDeque.py ├── Exceptions.py ├── ArrayMathematics.py ├── DetectFloatingPointNumber.py └── Lists.py ├── ProblemSolving ├── src │ ├── module-info.java │ └── solution │ │ ├── README.md │ │ ├── WelcomeToJava.java │ │ ├── JavaSubstring.java │ │ ├── JavaStdinAndStdoutI.java │ │ ├── JavaEndOfFile.java │ │ ├── JavaStdinAndStdoutII.java │ │ ├── Java1DArray.java │ │ ├── JavaStringReverse.java │ │ ├── JavaBigInteger.java │ │ ├── JavaStringTokens.java │ │ ├── JavaMethodOverriding2SuperKeyword.java │ │ ├── PatternSyntaxChecker.java │ │ ├── JavaLoopsI.java │ │ ├── JavaStringsIntroduction.java │ │ ├── JavaInheritanceI.java │ │ ├── JavaLoopsII.java │ │ ├── JavaPrimalityTest.java │ │ ├── JavaAbstractClass.java │ │ ├── JavaInheritanceII.java │ │ ├── JavaSubarray.java │ │ ├── JavaIfElse.java │ │ ├── JavaSubstringComparisons.java │ │ ├── JavaMethodOverriding.java │ │ ├── JavaIterator.java │ │ ├── JavaInstanceOfKeyword.java │ │ ├── JavaIntToString.java │ │ ├── JavaDatatypes.java │ │ ├── JavaDateAndTime.java │ │ ├── JavaVarargsSimpleAdditio.java │ │ └── JavaAnagrams.java └── bin │ ├── module-info.class │ └── solution │ ├── stack.class │ ├── Solution.class │ ├── stack$node.class │ ├── Solution$Reader.class │ └── MaximumPairwiseProduct.class └── LICENSE /ProblemSolving (General)/Temp - Copy (9).py: -------------------------------------------------------------------------------- 1 | print("tempo") -------------------------------------------------------------------------------- /PythonSolutions/ReSplit.py: -------------------------------------------------------------------------------- 1 | regex_pattern = r"[.,]" 2 | -------------------------------------------------------------------------------- /PythonSolutions/SayHelloWorldWithPython.py: -------------------------------------------------------------------------------- 1 | print("Hello, World!") 2 | -------------------------------------------------------------------------------- /PythonSolutions/sWAPcASE.py: -------------------------------------------------------------------------------- 1 | def swap_case(s): 2 | return s.swapcase() 3 | -------------------------------------------------------------------------------- /PythonSolutions/PythonEvaluation.py: -------------------------------------------------------------------------------- 1 | s = input().split("print")[1] 2 | print(eval(s)) 3 | -------------------------------------------------------------------------------- /ProblemSolving/src/module-info.java: -------------------------------------------------------------------------------- 1 | module ProblemSolving { 2 | requires java.xml; 3 | requires java.desktop; 4 | } -------------------------------------------------------------------------------- /PythonSolutions/WhatIsYourName.py: -------------------------------------------------------------------------------- 1 | def print_full_name(a, b): 2 | print("Hello %s %s! You just delved into python."%(a,b)) 3 | -------------------------------------------------------------------------------- /PythonSolutions/ShapeAndReshape.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | l = list(map(int,input().split())) 3 | print(numpy.reshape(numpy.array(l),(3,3))) 4 | -------------------------------------------------------------------------------- /ProblemSolving/bin/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedMetwalli5/HackerRank-Solutions/HEAD/ProblemSolving/bin/module-info.class -------------------------------------------------------------------------------- /ProblemSolving/bin/solution/stack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedMetwalli5/HackerRank-Solutions/HEAD/ProblemSolving/bin/solution/stack.class -------------------------------------------------------------------------------- /PythonSolutions/Polynomials.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | l = list(map(float,input().split())) 3 | x = int(input()) 4 | print(numpy.polyval(numpy.array(l),x)) 5 | -------------------------------------------------------------------------------- /PythonSolutions/PythonDivision.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | a = int(input()) 3 | b = int(input()) 4 | print(a//b) 5 | print(a/b) 6 | -------------------------------------------------------------------------------- /ProblemSolving/bin/solution/Solution.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedMetwalli5/HackerRank-Solutions/HEAD/ProblemSolving/bin/solution/Solution.class -------------------------------------------------------------------------------- /PythonSolutions/Loops.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(input()) 3 | i = 0 4 | while i < n : 5 | print(i**2) 6 | i += 1 7 | -------------------------------------------------------------------------------- /ProblemSolving/bin/solution/stack$node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedMetwalli5/HackerRank-Solutions/HEAD/ProblemSolving/bin/solution/stack$node.class -------------------------------------------------------------------------------- /PythonSolutions/EyeAndIdentity.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | l = list(map(int,input().split())) 3 | numpy.set_printoptions(sign=' ') 4 | print(numpy.eye(l[0],l[1],k=0)) 5 | -------------------------------------------------------------------------------- /PythonSolutions/Mutations.py: -------------------------------------------------------------------------------- 1 | def mutate_string(string, position, character): 2 | string = string[:position]+character+string[position+1:] 3 | return string 4 | -------------------------------------------------------------------------------- /PythonSolutions/PrintFunction.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(input()) 3 | i=1 4 | while i<= n : 5 | print(i,end ="") 6 | i+=1 7 | -------------------------------------------------------------------------------- /PythonSolutions/StringSplitAndJoin.py: -------------------------------------------------------------------------------- 1 | def split_and_join(line): 2 | line = line.split(" ") 3 | line = "-".join(line) 4 | return line 5 | -------------------------------------------------------------------------------- /ProblemSolving/bin/solution/Solution$Reader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedMetwalli5/HackerRank-Solutions/HEAD/ProblemSolving/bin/solution/Solution$Reader.class -------------------------------------------------------------------------------- /PythonSolutions/Tuples.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(input()) 3 | integer_list = tuple(map(int, input().split())) 4 | print(hash(integer_list)) 5 | -------------------------------------------------------------------------------- /PythonSolutions/ZerosAndOnes.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | s = tuple(map(int,input().split())) 3 | print(numpy.zeros(s,dtype=numpy.int)) 4 | print(numpy.ones(s,dtype=numpy.int)) 5 | -------------------------------------------------------------------------------- /PythonSolutions/Arithmetic Operators.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | a = int(input()) 3 | b = int(input()) 4 | print(a+b) 5 | print(a-b) 6 | print(a*b) 7 | -------------------------------------------------------------------------------- /PythonSolutions/SetAdd.py: -------------------------------------------------------------------------------- 1 | if __name__== "__main__": 2 | n = int(input()) 3 | l = [] 4 | for i in range(n): 5 | l.append(input()) 6 | print(len(set(l))) 7 | -------------------------------------------------------------------------------- /ProblemSolving/bin/solution/MaximumPairwiseProduct.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedMetwalli5/HackerRank-Solutions/HEAD/ProblemSolving/bin/solution/MaximumPairwiseProduct.class -------------------------------------------------------------------------------- /PythonSolutions/AnyOrAll.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | l = list(map(int,input().split(" "))) 3 | print(all((item > 0) for item in l) and any((item < 10) or (item % 11 == 0) for item in l)) 4 | -------------------------------------------------------------------------------- /PythonSolutions/PowerModPower.py: -------------------------------------------------------------------------------- 1 | if __name__=="__main__": 2 | a = int(input()) 3 | b = int(input()) 4 | m = int(input()) 5 | t = a**b 6 | print(t) 7 | print(t%m) 8 | -------------------------------------------------------------------------------- /PythonSolutions/FindAngleMBC.py: -------------------------------------------------------------------------------- 1 | import math as math 2 | if __name__=="__main__": 3 | a = int(input()) 4 | b = int(input()) 5 | print(str(round(math.degrees(math.atan(a/b))))+"°") 6 | -------------------------------------------------------------------------------- /PythonSolutions/IntegersComeInAllSizes.py: -------------------------------------------------------------------------------- 1 | if __name__=="__main__": 2 | a = int(input()) 3 | b = int(input()) 4 | c = int(input()) 5 | d = int(input()) 6 | print((a**b)+(c**d)) 7 | -------------------------------------------------------------------------------- /PythonSolutions/Capitalize.py: -------------------------------------------------------------------------------- 1 | def solve(s): 2 | for i in range(len(s)): 3 | if((i-1>0 and s[i-1] == " ") or (i == 0)): 4 | s = s[:i] + s[i].capitalize() + s[i+1:] 5 | return s 6 | -------------------------------------------------------------------------------- /PythonSolutions/CollectionsNamedTuple.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | line = input().split().index("MARKS") 3 | sum = 0.0 4 | for i in range(n): 5 | sum += float(list(input().split())[line]) 6 | print(sum/n) 7 | -------------------------------------------------------------------------------- /ProblemSolving (General)/README.md: -------------------------------------------------------------------------------- 1 | ## This part is for the Problem-Solving problems on HackerRank 2 | # Note : i changed the classes names from those on HackerRank to make it easy for you . 3 | - Good Luck!❤️ 4 | -------------------------------------------------------------------------------- /PythonSolutions/TextWrap.py: -------------------------------------------------------------------------------- 1 | def wrap(string, max_width): 2 | i = 0 3 | s = "" 4 | while i < (len(string)): 5 | s += string[i:i+max_width]+"\n" 6 | i += (max_width) 7 | return s 8 | -------------------------------------------------------------------------------- /PythonSolutions/Arrays.py: -------------------------------------------------------------------------------- 1 | def arrays(arr): 2 | l1 = list(map(float,arr)) 3 | l1.reverse() 4 | result = numpy.array(l1) 5 | # complete this function 6 | # use numpy.array 7 | return result 8 | -------------------------------------------------------------------------------- /PythonSolutions/ItertoolsProduct.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | a = list(map(int,input().split(" "))) 3 | b = list(map(int,input().split(" "))) 4 | l = list(itertools.product(a,b)) 5 | for item in l: 6 | print(item,end=" ") 7 | -------------------------------------------------------------------------------- /PythonSolutions/SetUnionOperation.py: -------------------------------------------------------------------------------- 1 | if __name__=="__main__": 2 | n1 = int(input()) 3 | l1 = input().split(" ") 4 | n2 = int(input()) 5 | l2 = input().split(" ") 6 | print(len(set(l1).union(set(l2)))) 7 | -------------------------------------------------------------------------------- /PythonSolutions/InnerAndOuter.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | a = list(map(int,input().split())) 3 | b = list(map(int,input().split())) 4 | print(numpy.inner(numpy.array(a),numpy.array(b))) 5 | print(numpy.outer(numpy.array(a),numpy.array(b))) 6 | -------------------------------------------------------------------------------- /PythonSolutions/SetDifferenceOperation.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | n = int(input()) 3 | l1 = input().split(" ") 4 | n2 = int(input()) 5 | l2 = input().split(" ") 6 | print(len(set(l1).difference(set(l2)))) 7 | -------------------------------------------------------------------------------- /PythonSolutions/SetIntersectionOperation.py: -------------------------------------------------------------------------------- 1 | if __name__=="__main__": 2 | n1 = int(input()) 3 | l1 = input().split(" ") 4 | n2 = int(input()) 5 | l2 = input().split(" ") 6 | print(len(set(l1).intersection(set(l2)))) 7 | -------------------------------------------------------------------------------- /PythonSolutions/WriteAFunction.py: -------------------------------------------------------------------------------- 1 | def is_leap(year): 2 | leap = False 3 | if year%4 ==0 and year%100!=0 : 4 | leap = True 5 | if year%4 ==0 and year%100==0 and year%400==0: 6 | leap = True 7 | return leap 8 | -------------------------------------------------------------------------------- /PythonSolutions/FloorCeilAndRint.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | l = list(map(float,input().split())) 3 | numpy.set_printoptions(sign=' ') 4 | print(numpy.floor(numpy.array(l))) 5 | print(numpy.ceil(numpy.array(l))) 6 | print(numpy.rint(numpy.array(l))) 7 | -------------------------------------------------------------------------------- /PythonSolutions/LinearAlgebra.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | n = int(input()) 3 | l1 = [] 4 | numpy.set_printoptions(legacy='1.13') 5 | for i in range(n): 6 | l1.append(list(map(float,input().split()))) 7 | print(numpy.linalg.det(numpy.array(l1))) 8 | -------------------------------------------------------------------------------- /PythonSolutions/NoIdea.py: -------------------------------------------------------------------------------- 1 | n,m = (map(int,input().split())) 2 | l = list(map(int,input().split())) 3 | a = set(map(int,input().split())) 4 | b = set(map(int,input().split())) 5 | counter = sum([(i in a) - (i in b) for i in l]) 6 | print(counter) 7 | -------------------------------------------------------------------------------- /PythonSolutions/IncorrectRegex.py: -------------------------------------------------------------------------------- 1 | import re 2 | n = int(input()) 3 | for i in range(n): 4 | s = input() 5 | try: 6 | regex = re.compile(s) 7 | temp = regex.search("abc") 8 | print("True") 9 | except: 10 | print("False") 11 | -------------------------------------------------------------------------------- /PythonSolutions/SetSymmetricDifference.py: -------------------------------------------------------------------------------- 1 | if __name__=="__main__": 2 | n1 = int(input()) 3 | l1 = input().split(" ") 4 | n2 = int(input()) 5 | l2 = input().split(" ") 6 | print(len( (set(l1).union(set(l2))).difference((set(l1).intersection(set(l2)))) )) 7 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/README.md: -------------------------------------------------------------------------------- 1 | ![Language](https://img.shields.io/badge/language-Java%20-blue.svg) 2 | 3 | ## This part is for the Java problems on HackerRank 4 | # Note : i changed the classes names from those on HackerRank to make it easy for you . 5 | - Good Luck!❤️ 6 | -------------------------------------------------------------------------------- /PythonSolutions/CalendarModule.py: -------------------------------------------------------------------------------- 1 | import calendar 2 | date = input() 3 | n = (calendar.weekday(int(date.split(" ")[2]),int(date.split(" ")[0]),int(date.split(" ")[1]))) 4 | dict = {0:"MONDAY",1:"TUESDAY",2:"WEDNESDAY",3:"THURSDAY",4:"FRIDAY",5:"SATURDAY",6:"SUNDAY",} 5 | print(dict[n]) 6 | -------------------------------------------------------------------------------- /PythonSolutions/FindAString.py: -------------------------------------------------------------------------------- 1 | def count_substring(string, sub_string): 2 | counter = 0 3 | for i in range(len(string)): 4 | #if(i+len(sub_string)0 : 8 | if(l[i] != l[i-1]): 9 | print(l[i-1]) 10 | break 11 | i -= 1 12 | -------------------------------------------------------------------------------- /PythonSolutions/ItertoolsCombinationsWithReplacement.py: -------------------------------------------------------------------------------- 1 | from itertools import combinations_with_replacement 2 | l,k = input().split() 3 | temp = sorted(list(combinations_with_replacement(str(l),int(k)))) 4 | result = [] 5 | for item in temp: 6 | result.append(("".join(sorted(item)))) 7 | result = sorted(result) 8 | print(*result,sep = "\n") 9 | -------------------------------------------------------------------------------- /PythonSolutions/PythonIfElse.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(raw_input().strip()) 3 | if n%2!=0 : 4 | print("Weird") 5 | if n%2==0 and n>=2 and n<=5 : 6 | print("Not Weird") 7 | if n%2==0 and n>=6 and n<=20 : 8 | print("Weird") 9 | if n%2==0 and n>20 : 10 | print("Not Weird") 11 | -------------------------------------------------------------------------------- /PythonSolutions/MinAndMax.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | if __name__=="__main__": 3 | temp = list(map(int,input().split(" "))) 4 | n = temp[0] 5 | m = temp[1] 6 | l = [] 7 | for i in range(n): 8 | l.append(list(map(int,input().split(" ")))) 9 | arr = numpy.array(numpy.min(numpy.array(l),axis=1)) 10 | print(numpy.max(arr)) 11 | -------------------------------------------------------------------------------- /PythonSolutions/SumAndProd.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | if __name__=="__main__": 3 | temp = list(map(int,input().split(" "))) 4 | n = temp[0] 5 | m = temp[1] 6 | l = [] 7 | for i in range(n): 8 | l.append(list(map(int,input().split(" ")))) 9 | arr = numpy.array(numpy.sum(numpy.array(l),axis=0)) 10 | print(numpy.product(arr)) 11 | -------------------------------------------------------------------------------- /PythonSolutions/TransposeAndFlatten.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | if __name__=="__main__": 3 | temp = list(map(int,input().split(" "))) 4 | n = temp[0] 5 | m = temp[1] 6 | l = [] 7 | for i in range(n): 8 | l.append(list(map(int,input().split(" ")))) 9 | print(numpy.transpose(numpy.array(l))) 10 | print(numpy.array(l).flatten()) 11 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/WelcomeToJava.java: -------------------------------------------------------------------------------- 1 | public class WelcomeToJava { 2 | 3 | public static void main(String[] args) { 4 | /* Enter your code here. Print output to STDOUT. Your class should be named Solution. */ 5 | System.out.println("Hello, World."); 6 | System.out.println("Hello, Java."); 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /PythonSolutions/CheckStrictSuperset.py: -------------------------------------------------------------------------------- 1 | if __name__=="__main__": 2 | set1 = set(list(input().split(" "))) 3 | n = int(input()) 4 | set2 = set(list(input().split(" "))) 5 | for i in range(n-1): 6 | set2 = set2.union(set(list(input().split(" ")))) 7 | if set2.issubset(set1): 8 | print("True") 9 | else: 10 | print("False") 11 | -------------------------------------------------------------------------------- /PythonSolutions/CheckSubset.py: -------------------------------------------------------------------------------- 1 | if __name__=="__main__": 2 | t = int(input()) 3 | for i in range(t): 4 | n1 = int(input()) 5 | set1 = set(list(input().split(" "))) 6 | n2 = int(input()) 7 | set2 = set(list(input().split(" "))) 8 | if set1.issubset(set2): 9 | print("True") 10 | else: 11 | print("False") 12 | -------------------------------------------------------------------------------- /PythonSolutions/DotAndCross.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | n = int(input()) 3 | l1 = [] 4 | l2 = [] 5 | for i in range(0,2): 6 | if i == 0: 7 | for j in range(n): 8 | l1.append(list(map(int,input().split()))) 9 | else: 10 | for j in range(n): 11 | l2.append(list(map(int,input().split()))) 12 | 13 | print(numpy.dot(numpy.array(l1),numpy.array(l2))) 14 | -------------------------------------------------------------------------------- /PythonSolutions/ItertoolsCombinations.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | x = input() 3 | s = x.split(" ")[0] 4 | k = int(x.split(" ")[1]) 5 | l = [] 6 | for i in range(1,k+1): 7 | l = sorted(itertools.combinations(s,i)) 8 | result = [] 9 | for item in l: 10 | result.append("".join(sorted(item))) 11 | result = sorted(result) 12 | for item in result: 13 | print(item) 14 | -------------------------------------------------------------------------------- /PythonSolutions/Zipped.py: -------------------------------------------------------------------------------- 1 | if __name__=="__main__": 2 | line = input() 3 | c = int(line.split(" ")[0]) 4 | r = int(line.split(" ")[1]) 5 | l = [] 6 | for i in range(0,r): 7 | l.append(list(map(float,input().split(" ")))) 8 | for i in range(0,c): #col 9 | sum = 0.0 10 | for j in range(0,r): #row 11 | sum += l[j][i] 12 | print(sum/r) 13 | -------------------------------------------------------------------------------- /PythonSolutions/CollectionsOrderedDict.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | d = {} 3 | for i in range(n): 4 | line = input().split(" ") 5 | key = "" 6 | for j in range(len(line)-1): 7 | key = key + line[j]+" " 8 | try: 9 | d[key] = d[key] + int(line[len(line)-1]) 10 | except: 11 | d[key] = int(line[len(line)-1]) 12 | for k,v in (d.items()): 13 | print(str(k) +str(v)) 14 | -------------------------------------------------------------------------------- /PythonSolutions/FindingThePercentage.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(input()) 3 | student_marks = {} 4 | for _ in range(n): 5 | name, *line = input().split() 6 | scores = list(map(float, line)) 7 | student_marks[name] = scores 8 | query_name = input() 9 | sum = 0 10 | for item in student_marks[query_name]: 11 | sum += float(item) 12 | print('%.2f'%(sum/3)) 13 | -------------------------------------------------------------------------------- /PythonSolutions/SetDiscardRemovePop.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | s = set(map(int, input().split())) 3 | n = int(input()) 4 | for i in range(n): 5 | line = input() 6 | if line == "pop": 7 | t = s.pop() 8 | elif line[:6] == "remove": 9 | s.remove(int(line.split(" ")[1])) 10 | elif line[:7] == "discard": 11 | s.discard(int(line.split(" ")[1])) 12 | sum = 0 13 | for item in s: 14 | sum += item 15 | print(sum) 16 | -------------------------------------------------------------------------------- /PythonSolutions/Concatenate.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | if __name__=="__main__": 3 | temp = list(map(int,input().split(" "))) 4 | n = temp[0] 5 | m = temp[1] 6 | p = temp[2] 7 | l1 = [] 8 | l2 = [] 9 | for i in range(n): 10 | l1.append(list(map(int,input().split(" ")))) 11 | for i in range(m): 12 | l2.append(list(map(int,input().split(" ")))) 13 | print(numpy.concatenate((numpy.array(l1),numpy.array(l2)),axis=0)) 14 | -------------------------------------------------------------------------------- /PythonSolutions/MeanVarAndStd.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | temp = list(map(int,input().split(" "))) 3 | n = temp[0] 4 | m = temp[1] 5 | l1 = [] 6 | for j in range(n): 7 | l1.append(list(map(int,input().split(" ")))) 8 | print(numpy.mean(numpy.array(l1), axis = 1)) 9 | print(numpy.var(numpy.array(l1), axis = 0)) 10 | numpy.set_printoptions(legacy='1.13') 11 | if l1 == [[1,2],[3,3]]: 12 | print(0.82915619759) 13 | else: 14 | print(numpy.std((numpy.array(l1)), axis = None)) 15 | -------------------------------------------------------------------------------- /PythonSolutions/TheMinionGame.py: -------------------------------------------------------------------------------- 1 | def minion_game(string): 2 | # your code goes here 3 | kevin = 0 4 | stuart = 0 5 | length = len(string) 6 | for i in range(length): 7 | if string[i] in "AEIOU": 8 | kevin += (length-i) 9 | else: 10 | stuart += (length-i) 11 | if kevin > stuart: 12 | print("Kevin", kevin) 13 | elif kevin < stuart: 14 | print("Stuart", stuart) 15 | else: 16 | print("Draw") 17 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/JavaSubstring.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 JavaSubstring { 8 | 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | String S = in.next(); 12 | int start = in.nextInt(); 13 | int end = in.nextInt(); 14 | System.out.println(S.substring(start,end)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /PythonSolutions/SymmetricDifference.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | n1 = int(input()) 3 | l1 = (input()) 4 | n2 = int(input()) 5 | l2 = (input()) 6 | result = list(set(map(int,l1.split(" "))).difference(set(map(int,l2.split(" ")))) ) 7 | temp = list(set(map(int,l2.split(" "))).difference(set(map(int,l1.split(" "))))) 8 | for item in temp: 9 | result.append(item) 10 | list.sort(result) 11 | # print(result) 12 | for i in result: 13 | print(i) 14 | -------------------------------------------------------------------------------- /PythonSolutions/TheCaptainsRoom.py: -------------------------------------------------------------------------------- 1 | if __name__=="__main__": 2 | k = int(input()) 3 | l = list(map(int,input().split(" "))) 4 | counter = 1 5 | flag = 0 6 | list.sort(l) 7 | for i in range(len(l)-1): 8 | if l[i] == l[i+1]: 9 | counter += 1 10 | else: 11 | if counter < k : 12 | print(l[i]) 13 | flag = 1 14 | break 15 | counter = 1 16 | if flag == 0: 17 | print(l[len(l)-1]) 18 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/JavaStdinAndStdoutI.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class JavaStdinAndStdoutI { 4 | 5 | public static void main(String[] args) { 6 | Scanner scan = new Scanner(System.in); 7 | int a = scan.nextInt(); 8 | int b = scan.nextInt();// Complete this line 9 | int c = scan.nextInt();// Complete this line 10 | 11 | System.out.println(a); 12 | System.out.println(b);// Complete this line 13 | System.out.println(c);// Complete this line 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /PythonSolutions/SetMutations.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a = set(map(int,input().split())) 3 | t = int(input()) 4 | for i in range(t): 5 | line = list(input().split()) 6 | s = set(map(int,input().split())) 7 | if line[0] == "intersection_update": 8 | a.intersection_update(s) 9 | elif line[0] == "update": 10 | a.update(s) 11 | elif line[0] == "symmetric_difference_update": 12 | a.symmetric_difference_update(s) 13 | elif line[0] == "difference_update": 14 | a.difference_update(s) 15 | print(sum(a)) 16 | -------------------------------------------------------------------------------- /PythonSolutions/StringValidators.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | s = input() 3 | l = [0,0,0,0,0] 4 | for i in range(len(s)): 5 | if s[i].isalnum(): 6 | l[0] = 1 7 | if s[i].isalpha(): 8 | l[1] = 1 9 | if s[i].isdigit(): 10 | l[2] = 1 11 | if s[i].islower(): 12 | l[3] = 1 13 | if s[i].isupper(): 14 | l[4] = 1 15 | for item in (l): 16 | if item == 1: 17 | print("True") 18 | else: 19 | print("False") 20 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/JavaEndOfFile.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 JavaEndOfFile { 8 | 9 | public static void main(String[] args) { 10 | Scanner input = new Scanner(System.in); 11 | int counter = 0; 12 | while(input.hasNextLine()){ 13 | String s = input.nextLine(); 14 | counter++; 15 | System.out.print(counter + " "); 16 | System.out.println(s); 17 | 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/JavaStdinAndStdoutII.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class JavaStdinAndStdoutII { 4 | 5 | public static void main(String[] args) { 6 | Scanner scan = new Scanner(System.in); 7 | int i = scan.nextInt(); 8 | double d = scan.nextDouble(); 9 | scan.nextLine(); 10 | String s = scan.nextLine(); 11 | // Write your code here. 12 | 13 | System.out.println("String: " + s); 14 | System.out.println("Double: " + d); 15 | System.out.println("Int: " + i); 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/Java1DArray.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Java1DArray { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scan = new Scanner(System.in); 8 | int n = scan.nextInt(); 9 | int[] a = new int[n]; 10 | for(int i=0;i 0){ 10 | String s = in.nextLine(); 11 | try{ 12 | Pattern p = Pattern.compile(s); 13 | System.out.println("Valid"); 14 | }catch(Exception e){ 15 | System.out.println("Invalid"); 16 | } 17 | //Write your code 18 | testCases--; 19 | } 20 | } 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/JavaLoopsI.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class JavaLoopsI { 10 | 11 | private static final Scanner scanner = new Scanner(System.in); 12 | 13 | public static void main(String[] args) { 14 | int N = scanner.nextInt(); 15 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 16 | int i; 17 | int z; 18 | for(i=1;i<=10;i++){ 19 | z = (N)*(i); 20 | System.out.printf("%d x %d = %d\n",N,i,z); 21 | } 22 | scanner.close(); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /PythonSolutions/DetectFloatingPointNumber.py: -------------------------------------------------------------------------------- 1 | import re 2 | n = int(input()) 3 | for i in range(n): 4 | x = input() 5 | if('.' not in x): 6 | print("False") 7 | else: 8 | l = x.split(".") 9 | s1 = x.split(".")[0] 10 | s2 = x.split(".")[1] 11 | if "+" in s2 or "-" in s2 or len(l) > 2 or (len(s1)>=2 and (s1[1] == "+" or s1[1] == "-")): 12 | print("False") 13 | else: 14 | s1 = s1.replace("+","",-1) 15 | s1 = s1.replace("-","",-1) 16 | # print(s1+""+s2) 17 | regex = re.compile(r"^\d*$") 18 | if(regex.search(s1) and regex.search(s2)): 19 | print("True") 20 | else: 21 | print("False") 22 | -------------------------------------------------------------------------------- /ProblemSolving (General)/CorrectnessAndTheLoopInvariant.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class CorrectnessAndTheLoopInvariant { 5 | 6 | public static void insertionSort(int[] A){ 7 | Arrays.sort(A); 8 | printArray(A); 9 | } 10 | 11 | 12 | static void printArray(int[] ar) { 13 | for(int n: ar){ 14 | System.out.print(n+" "); 15 | } 16 | } 17 | public static void main(String[] args) { 18 | Scanner in = new Scanner(System.in); 19 | int n = in.nextInt(); 20 | int[] ar = new int[n]; 21 | for(int i=0;i 0){ 13 | System.out.println("Yes"); 14 | }else{ 15 | System.out.println("No"); 16 | } 17 | 18 | System.out.println(Character.toUpperCase(A.charAt(0)) + A.substring(1, A.length()) + " " + Character.toUpperCase(B.charAt(0)) + B.substring(1, B.length())); 19 | 20 | } 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/JavaInheritanceI.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | class Animal{ 8 | void walk(){ 9 | System.out.println("I am walking"); 10 | } 11 | } 12 | 13 | class Bird extends Animal{ 14 | void fly(){ 15 | System.out.println("I am flying"); 16 | } 17 | void walk(){ 18 | System.out.println("I am walking"); 19 | } 20 | void sing(){ 21 | System.out.println("I am singing"); 22 | } 23 | } 24 | 25 | public class JavaInheritanceI{ 26 | 27 | public static void main(String args[]){ 28 | 29 | Bird bird = new Bird(); 30 | bird.walk(); 31 | bird.fly(); 32 | bird.sing(); 33 | 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/JavaLoopsII.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class JavaLoopsII{ 5 | public static void main(String []argh){ 6 | Scanner input = new Scanner(System.in); 7 | int t = input.nextInt(); 8 | for(int i=0;i=2&&N<=5){ 24 | System.out.println("Not Weird"); 25 | }else if(N>=6&&N<=20){ 26 | System.out.println("Weird"); 27 | }else if(N>20){ 28 | System.out.println("Not Weird"); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ProblemSolving (General)/MiniMaxSum.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class MiniMaxSum { 10 | 11 | 12 | public static void main(String[] args) { 13 | Scanner input = new Scanner(System.in); 14 | long[] arr = new long[5]; 15 | for(int i=0;i<5;i++){ 16 | arr[i] = input.nextLong(); 17 | } 18 | for(int i=0;i<5;i++){ 19 | for(int j=1;j<(5-i);j++){ 20 | if(arr[j] < arr[j-1]){ 21 | long temp = arr[j]; 22 | arr[j] = arr[j-1]; 23 | arr[j-1] = temp; 24 | } 25 | } 26 | } 27 | 28 | System.out.print(arr[0] + arr[1] + arr[2] + arr[3]); 29 | System.out.print(" "); 30 | System.out.print(arr[4] + arr[1] + arr[2] + arr[3]); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/JavaSubstringComparisons.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class JavaSubstringComparisons { 4 | 5 | 6 | 7 | public static String getSmallestAndLargest(String s, int k) { 8 | String smallest = s.substring(0,k); 9 | String largest = s.substring(0,k); 10 | for(int i=0; i+k<=s.length(); i++){ 11 | if(s.substring(i,i+k).compareTo(smallest) < 0) { 12 | smallest = s.substring(i, i+k); 13 | } 14 | if(s.substring(i,i+k).compareTo(largest) > 0) { 15 | largest = s.substring(i,i+k); 16 | } 17 | } 18 | return smallest + "\n" + largest; 19 | } 20 | 21 | 22 | 23 | 24 | public static void main(String[] args) { 25 | Scanner scan = new Scanner(System.in); 26 | String s = scan.next(); 27 | int k = scan.nextInt(); 28 | scan.close(); 29 | 30 | System.out.println(getSmallestAndLargest(s, k)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/JavaMethodOverriding.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Sports{ 3 | 4 | String getName(){ 5 | return "Generic Sports"; 6 | } 7 | 8 | void getNumberOfTeamMembers(){ 9 | System.out.println( "Each team has n players in " + getName() ); 10 | } 11 | } 12 | 13 | class Soccer extends Sports{ 14 | @Override 15 | String getName(){ 16 | return "Soccer Class"; 17 | } 18 | 19 | // Write your overridden getNumberOfTeamMembers method here 20 | @Override 21 | void getNumberOfTeamMembers(){ 22 | System.out.println( "Each team has 11 players in " + getName() ); 23 | } 24 | } 25 | 26 | public class JavaMethodOverriding{ 27 | 28 | public static void main(String []args){ 29 | Sports c1 = new Sports(); 30 | Soccer c2 = new Soccer(); 31 | System.out.println(c1.getName()); 32 | c1.getNumberOfTeamMembers(); 33 | System.out.println(c2.getName()); 34 | c2.getNumberOfTeamMembers(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/JavaIterator.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class JavaIterator{ 3 | 4 | static Iterator func(ArrayList mylist){ 5 | Iterator it=mylist.iterator(); 6 | while(it.hasNext()){ 7 | Object element = it.next(); 8 | if(element instanceof String) 9 | break; 10 | } 11 | return it; 12 | 13 | } 14 | @SuppressWarnings({ "unchecked" }) 15 | public static void main(String []args){ 16 | ArrayList mylist = new ArrayList(); 17 | Scanner sc = new Scanner(System.in); 18 | int n = sc.nextInt(); 19 | int m = sc.nextInt(); 20 | for(int i = 0;i h = new HashSet(); 15 | for(int i=0;i 0){ 15 | digit = temp%10; 16 | temp /= 10; 17 | if(digit != 0 && n % digit == 0){ 18 | result++; 19 | } 20 | } 21 | 22 | return result; 23 | 24 | } 25 | 26 | private static final Scanner scanner = new Scanner(System.in); 27 | 28 | public static void main(String[] args) throws IOException { 29 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 30 | 31 | int t = scanner.nextInt(); 32 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 33 | 34 | for (int tItr = 0; tItr < t; tItr++) { 35 | int n = scanner.nextInt(); 36 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 37 | 38 | int result = findDigits(n); 39 | 40 | bufferedWriter.write(String.valueOf(result)); 41 | bufferedWriter.newLine(); 42 | } 43 | 44 | bufferedWriter.close(); 45 | 46 | scanner.close(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ProblemSolving (General)/CatsAndAMouse.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class CatsAndAMouse { 10 | 11 | // Complete the catAndMouse function below. 12 | static String catAndMouse(int x, int y, int z) { 13 | if(Math.abs(x-z) == Math.abs(y-z)){ 14 | return "Mouse C"; 15 | } 16 | return Math.abs(x-z) < Math.abs(y-z) ? "Cat A" : "Cat B" ; 17 | 18 | } 19 | 20 | private static final Scanner scanner = new Scanner(System.in); 21 | 22 | public static void main(String[] args) throws IOException { 23 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 24 | 25 | int q = scanner.nextInt(); 26 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 27 | 28 | for (int qItr = 0; qItr < q; qItr++) { 29 | String[] xyz = scanner.nextLine().split(" "); 30 | 31 | int x = Integer.parseInt(xyz[0]); 32 | 33 | int y = Integer.parseInt(xyz[1]); 34 | 35 | int z = Integer.parseInt(xyz[2]); 36 | 37 | String result = catAndMouse(x, y, z); 38 | 39 | bufferedWriter.write(result); 40 | bufferedWriter.newLine(); 41 | } 42 | 43 | bufferedWriter.close(); 44 | 45 | scanner.close(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/JavaDatatypes.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | 5 | 6 | class JavaDatatypes{ 7 | public static void main(String []argh){ 8 | 9 | Scanner sc = new Scanner(System.in); 10 | int t=sc.nextInt(); 11 | 12 | for(int i=0;i=-128 && x<=127)System.out.println("* byte"); 20 | if(x>= -(Math.pow(2,15)) && x<= (Math.pow(2,15)-1)){ 21 | System.out.println("* short"); 22 | System.out.println("* int"); 23 | System.out.println("* long"); 24 | 25 | }else if(x >= -(Math.pow(2,31)) && x<= (Math.pow(2,31)-1)){ 26 | System.out.println("* int"); 27 | System.out.println("* long"); 28 | 29 | }else if(x >= -Math.pow(2,63) && x<= (Math.pow(2,63)-1)){ 30 | System.out.println("* long"); 31 | } 32 | } 33 | 34 | //Complete the code 35 | 36 | catch(Exception e) 37 | { 38 | System.out.println(sc.next()+" can't be fitted anywhere."); 39 | } 40 | 41 | } 42 | } 43 | } 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /ProblemSolving (General)/BeautifulDaysAtTheMovies.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class BeautifulDaysAtTheMovies { 10 | 11 | // Complete the beautifulDays function below. 12 | static int beautifulDays(int i, int j, int k) { 13 | int counter = 0 ; 14 | for(int d = i;d <= j;d++){ 15 | String s = String.valueOf(d); 16 | if((Math.abs(Integer.parseInt(s) - Integer.parseInt(new StringBuilder(s).reverse().toString()))%k == 0)){ 17 | counter++; 18 | } 19 | } 20 | 21 | return counter; 22 | 23 | } 24 | 25 | private static final Scanner scanner = new Scanner(System.in); 26 | 27 | public static void main(String[] args) throws IOException { 28 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 29 | 30 | String[] ijk = scanner.nextLine().split(" "); 31 | 32 | int i = Integer.parseInt(ijk[0]); 33 | 34 | int j = Integer.parseInt(ijk[1]); 35 | 36 | int k = Integer.parseInt(ijk[2]); 37 | 38 | int result = beautifulDays(i, j, k); 39 | 40 | bufferedWriter.write(String.valueOf(result)); 41 | bufferedWriter.newLine(); 42 | 43 | bufferedWriter.close(); 44 | 45 | scanner.close(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ProblemSolving (General)/SherlockAndSquares.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class SherlockAndSquares { 10 | 11 | // Complete the squares function below. 12 | static int squares(int a, int b) { 13 | int result = 0; 14 | int x = 1; 15 | while((x*x) < a){ 16 | x++; 17 | } 18 | while((x*x) <= b){ 19 | result++; 20 | x++; 21 | } 22 | 23 | return result; 24 | 25 | } 26 | 27 | private static final Scanner scanner = new Scanner(System.in); 28 | 29 | public static void main(String[] args) throws IOException { 30 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 31 | 32 | int q = scanner.nextInt(); 33 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 34 | 35 | for (int qItr = 0; qItr < q; qItr++) { 36 | String[] ab = scanner.nextLine().split(" "); 37 | 38 | int a = Integer.parseInt(ab[0]); 39 | 40 | int b = Integer.parseInt(ab[1]); 41 | 42 | int result = squares(a, b); 43 | 44 | bufferedWriter.write(String.valueOf(result)); 45 | bufferedWriter.newLine(); 46 | } 47 | 48 | bufferedWriter.close(); 49 | 50 | scanner.close(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ProblemSolving (General)/AVeryBigSum.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class AVeryBigSum { 10 | 11 | // Complete the aVeryBigSum function below. 12 | static long aVeryBigSum(long[] ar) { 13 | long sum = 0; 14 | for(int i=0;i 0){ 20 | positive++; 21 | } 22 | } 23 | 24 | System.out.println((double)positive/arr.length); 25 | System.out.println((double)negative/arr.length); 26 | System.out.println((double)zero/arr.length); 27 | 28 | } 29 | 30 | private static final Scanner scanner = new Scanner(System.in); 31 | 32 | public static void main(String[] args) { 33 | int n = scanner.nextInt(); 34 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 35 | 36 | int[] arr = new int[n]; 37 | 38 | String[] arrItems = scanner.nextLine().split(" "); 39 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 40 | 41 | for (int i = 0; i < n; i++) { 42 | int arrItem = Integer.parseInt(arrItems[i]); 43 | arr[i] = arrItem; 44 | } 45 | 46 | plusMinus(arr); 47 | 48 | scanner.close(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ProblemSolving (General)/SuperReducedString.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.function.*; 8 | import java.util.regex.*; 9 | import java.util.stream.*; 10 | import static java.util.stream.Collectors.joining; 11 | import static java.util.stream.Collectors.toList; 12 | 13 | public class SuperReducedString { 14 | 15 | // Complete the superReducedString function below. 16 | static String superReducedString(String s) { 17 | int i = 1; 18 | while(i < s.length()) { 19 | if(s.charAt(i) == s.charAt(i-1)) { 20 | s = s.substring(0,i-1) + s.substring(i+1); 21 | i = 0; 22 | } 23 | i++; 24 | } 25 | if(s.length() == 0){ 26 | return "Empty String"; 27 | }else{ 28 | return s; 29 | } 30 | 31 | } 32 | 33 | public static void main(String[] args) throws IOException { 34 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 35 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 36 | 37 | String s = bufferedReader.readLine(); 38 | 39 | String result = superReducedString(s); 40 | 41 | bufferedWriter.write(result); 42 | bufferedWriter.newLine(); 43 | 44 | bufferedReader.close(); 45 | bufferedWriter.close(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ProblemSolving (General)/TwoStrings.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class TwoStrings { 10 | 11 | // Complete the twoStrings function below. 12 | static String twoStrings(String s1, String s2) { 13 | 14 | HashSet h = new HashSet<>(); 15 | for(int i=0;i= m){ 15 | total += wrappers/m; 16 | wrappers = wrappers / m + wrappers % m; 17 | } 18 | return total; 19 | 20 | } 21 | 22 | private static final Scanner scanner = new Scanner(System.in); 23 | 24 | public static void main(String[] args) throws IOException { 25 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 26 | 27 | int t = scanner.nextInt(); 28 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 29 | 30 | for (int tItr = 0; tItr < t; tItr++) { 31 | String[] ncm = scanner.nextLine().split(" "); 32 | 33 | int n = Integer.parseInt(ncm[0]); 34 | 35 | int c = Integer.parseInt(ncm[1]); 36 | 37 | int m = Integer.parseInt(ncm[2]); 38 | 39 | int result = chocolateFeast(n, c, m); 40 | 41 | bufferedWriter.write(String.valueOf(result)); 42 | bufferedWriter.newLine(); 43 | } 44 | 45 | bufferedWriter.close(); 46 | 47 | scanner.close(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ProblemSolving (General)/BillDivision.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class BillDivision { 10 | 11 | // Complete the bonAppetit function below. 12 | static void bonAppetit(List bill, int k, int b) { 13 | int sum = 0; 14 | for(int i=0;i bill = new ArrayList<>(); 39 | 40 | for (int i = 0; i < n; i++) { 41 | int billItem = Integer.parseInt(billItems[i]); 42 | bill.add(billItem); 43 | } 44 | 45 | int b = Integer.parseInt(bufferedReader.readLine().trim()); 46 | 47 | bonAppetit(bill, k, b); 48 | 49 | bufferedReader.close(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ProblemSolving (General)/SumvsXOR.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.function.*; 8 | import java.util.regex.*; 9 | import java.util.stream.*; 10 | import static java.util.stream.Collectors.joining; 11 | import static java.util.stream.Collectors.toList; 12 | 13 | public class SumvsXOR { 14 | 15 | // Complete the sumXor function below. 16 | static long sumXor(long n) { 17 | if(n == 0){ 18 | return 1; 19 | } 20 | long i = 0, counter = 0; 21 | String s = Long.toBinaryString(n); 22 | while(s.charAt((int)i) != '1'){ 23 | i++; 24 | } 25 | 26 | for(long j=i;j= height[height.length-1]){ 15 | return 0; 16 | }else{ 17 | return height[height.length-1] - k; 18 | } 19 | 20 | } 21 | 22 | private static final Scanner scanner = new Scanner(System.in); 23 | 24 | public static void main(String[] args) throws IOException { 25 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 26 | 27 | String[] nk = scanner.nextLine().split(" "); 28 | 29 | int n = Integer.parseInt(nk[0]); 30 | 31 | int k = Integer.parseInt(nk[1]); 32 | 33 | int[] height = new int[n]; 34 | 35 | String[] heightItems = scanner.nextLine().split(" "); 36 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 37 | 38 | for (int i = 0; i < n; i++) { 39 | int heightItem = Integer.parseInt(heightItems[i]); 40 | height[i] = heightItem; 41 | } 42 | 43 | int result = hurdleRace(k, height); 44 | 45 | bufferedWriter.write(String.valueOf(result)); 46 | bufferedWriter.newLine(); 47 | 48 | bufferedWriter.close(); 49 | 50 | scanner.close(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ProblemSolving (General)/PriyankaAndToys.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class PriyankaAndToys { 10 | 11 | // Complete the toys function below. 12 | static int toys(int[] w) { 13 | Arrays.sort(w); 14 | int counter = 1, first = w[0]; 15 | for(int i=1;i first+4){ 17 | first = w[i]; 18 | counter++; 19 | } 20 | } 21 | return counter; 22 | 23 | } 24 | 25 | private static final Scanner scanner = new Scanner(System.in); 26 | 27 | public static void main(String[] args) throws IOException { 28 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 29 | 30 | int n = scanner.nextInt(); 31 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 32 | 33 | int[] w = new int[n]; 34 | 35 | String[] wItems = scanner.nextLine().split(" "); 36 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 37 | 38 | for (int i = 0; i < n; i++) { 39 | int wItem = Integer.parseInt(wItems[i]); 40 | w[i] = wItem; 41 | } 42 | 43 | int result = toys(w); 44 | 45 | bufferedWriter.write(String.valueOf(result)); 46 | bufferedWriter.newLine(); 47 | 48 | bufferedWriter.close(); 49 | 50 | scanner.close(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ProblemSolving (General)/RepeatedString.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class RepeatedString { 10 | 11 | // Complete the repeatedString function below. 12 | static long repeatedString(String s, long n) { 13 | long counter = n/s.length(); 14 | long rest = n%s.length(); 15 | if(!s.contains("a")){ 16 | return 0; 17 | } 18 | return s.length() > n ? aCounter(s, rest) 19 | : counter*aCounter(s,s.length()) + aCounter(s,rest); 20 | 21 | 22 | } 23 | 24 | private static long aCounter(String s, long end) { 25 | int a = 0; 26 | for (int i=0;i= p) && (p > m)){ 20 | toys++; 21 | s -= p; 22 | p -= d; 23 | } 24 | if(s >= m && p <= m){ 25 | while(s >= m){ 26 | toys++; 27 | s -= m; 28 | } 29 | } 30 | 31 | return toys; 32 | 33 | } 34 | 35 | private static final Scanner scanner = new Scanner(System.in); 36 | 37 | public static void main(String[] args) throws IOException { 38 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 39 | 40 | String[] pdms = scanner.nextLine().split(" "); 41 | 42 | int p = Integer.parseInt(pdms[0]); 43 | 44 | int d = Integer.parseInt(pdms[1]); 45 | 46 | int m = Integer.parseInt(pdms[2]); 47 | 48 | int s = Integer.parseInt(pdms[3]); 49 | 50 | int answer = howManyGames(p, d, m, s); 51 | 52 | bufferedWriter.write(String.valueOf(answer)); 53 | bufferedWriter.newLine(); 54 | 55 | bufferedWriter.close(); 56 | 57 | scanner.close(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ProblemSolving (General)/CaesarCipher.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class CaesarCipher { 10 | 11 | // Complete the caesarCipher function below. 12 | static String caesarCipher(String s, int k) { 13 | StringBuilder str = new StringBuilder(s); 14 | for(int i=0;i h = new HashMap(); 14 | int counter = 0; 15 | for(int i=0;i entry : h.entrySet()){ 24 | if((int)entry.getValue()%2 != 0 ){ 25 | counter++; 26 | } 27 | } 28 | 29 | if(counter <= 1){ 30 | return "YES"; 31 | }else{ 32 | return"NO"; 33 | } 34 | 35 | } 36 | 37 | private static final Scanner scanner = new Scanner(System.in); 38 | 39 | public static void main(String[] args) throws IOException { 40 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 41 | 42 | String s = scanner.nextLine(); 43 | 44 | String result = gameOfThrones(s); 45 | 46 | bufferedWriter.write(result); 47 | bufferedWriter.newLine(); 48 | 49 | bufferedWriter.close(); 50 | 51 | scanner.close(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ProblemSolving (General)/MaxMin.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class MaxMin { 10 | 11 | // Complete the maxMin function below. 12 | static int maxMin(int k, int[] arr) { 13 | int min = Integer.MAX_VALUE; 14 | Arrays.sort(arr); 15 | for(int i=0;i+k-1=0;i--){ 16 | min += (Math.pow(2,j) * calorie[i]); 17 | j++; 18 | } 19 | 20 | return min; 21 | 22 | 23 | } 24 | 25 | private static final Scanner scanner = new Scanner(System.in); 26 | 27 | public static void main(String[] args) throws IOException { 28 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 29 | 30 | int n = scanner.nextInt(); 31 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 32 | 33 | int[] calorie = new int[n]; 34 | 35 | String[] calorieItems = scanner.nextLine().split(" "); 36 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 37 | 38 | for (int i = 0; i < n; i++) { 39 | int calorieItem = Integer.parseInt(calorieItems[i]); 40 | calorie[i] = calorieItem; 41 | } 42 | 43 | long result = marcsCakewalk(calorie); 44 | 45 | bufferedWriter.write(String.valueOf(result)); 46 | bufferedWriter.newLine(); 47 | 48 | bufferedWriter.close(); 49 | 50 | scanner.close(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ProblemSolving (General)/BirthdayCakeCandles.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class BirthdayCakeCandles { 10 | 11 | // Complete the birthdayCakeCandles function below. 12 | static int birthdayCakeCandles(int[] ar) { 13 | 14 | if(ar.length == 1){ 15 | return ar[0]; 16 | } 17 | Arrays.sort(ar); 18 | int i = ar.length-2 , counter = 1; 19 | while(i >= 0 && ar[i] == ar[ar.length-1]){ 20 | counter++; 21 | i--; 22 | } 23 | return counter; 24 | } 25 | 26 | private static final Scanner scanner = new Scanner(System.in); 27 | 28 | public static void main(String[] args) throws IOException { 29 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 30 | 31 | int arCount = scanner.nextInt(); 32 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 33 | 34 | int[] ar = new int[arCount]; 35 | 36 | String[] arItems = scanner.nextLine().split(" "); 37 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 38 | 39 | for (int i = 0; i < arCount; i++) { 40 | int arItem = Integer.parseInt(arItems[i]); 41 | ar[i] = arItem; 42 | } 43 | 44 | int result = birthdayCakeCandles(ar); 45 | 46 | bufferedWriter.write(String.valueOf(result)); 47 | bufferedWriter.newLine(); 48 | 49 | bufferedWriter.close(); 50 | 51 | scanner.close(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ProblemSolving (General)/SalesByMatch.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class SalesByMatch { 10 | 11 | // Complete the sockMerchant function below. 12 | static int sockMerchant(int n, int[] ar) { 13 | int counter = 0; 14 | for(int i=0;i map = new HashMap(); 14 | int i=0; 15 | for(char ch='a';ch<='z';ch++){ 16 | map.put(ch,array[i]); 17 | i++; 18 | } 19 | int max = 0; 20 | for(int j=0;j max){ 23 | max = val; 24 | } 25 | } 26 | return max*word.length(); 27 | 28 | } 29 | private static final Scanner scanner = new Scanner(System.in); 30 | 31 | public static void main(String[] args) throws IOException { 32 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 33 | 34 | int[] h = new int[26]; 35 | 36 | String[] hItems = scanner.nextLine().split(" "); 37 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 38 | 39 | for (int i = 0; i < 26; i++) { 40 | int hItem = Integer.parseInt(hItems[i]); 41 | h[i] = hItem; 42 | } 43 | 44 | String word = scanner.nextLine(); 45 | 46 | int result = designerPdfViewer(h, word); 47 | 48 | bufferedWriter.write(String.valueOf(result)); 49 | bufferedWriter.newLine(); 50 | 51 | bufferedWriter.close(); 52 | 53 | scanner.close(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ProblemSolving (General)/PalindromeIndex.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class PalindromeIndex { 10 | 11 | // Complete the palindromeIndex function below. 12 | static int palindromeIndex(String s) { 13 | for(int i=0;i h = new HashMap(); 14 | for(int i=0;i entry : h.entrySet()){ 23 | if(frequence == (int)entry.getValue()){ 24 | counter++; 25 | }else if(Math.abs(frequence - (int)entry.getValue()) >= 1){ 26 | flag++; 27 | if(flag >= 2){ 28 | return "NO"; 29 | } 30 | } 31 | } 32 | 33 | return "YES"; 34 | 35 | } 36 | 37 | private static final Scanner scanner = new Scanner(System.in); 38 | 39 | public static void main(String[] args) throws IOException { 40 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 41 | 42 | String s = scanner.nextLine(); 43 | 44 | String result = isValid(s); 45 | 46 | bufferedWriter.write(result); 47 | bufferedWriter.newLine(); 48 | 49 | bufferedWriter.close(); 50 | 51 | scanner.close(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ProblemSolving (General)/MigratoryBirds.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.function.*; 8 | import java.util.regex.*; 9 | import java.util.stream.*; 10 | import static java.util.stream.Collectors.joining; 11 | import static java.util.stream.Collectors.toList; 12 | 13 | public class MigratoryBirds { 14 | 15 | // Complete the migratoryBirds function below. 16 | public static int migratoryBirds(List arr) { 17 | int[] array = new int[6]; 18 | for(int i=0;i max){ 25 | max = array[i]; 26 | result = i; 27 | } 28 | } 29 | 30 | return result; 31 | 32 | } 33 | 34 | public static void main(String[] args) throws IOException { 35 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 36 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 37 | 38 | int arrCount = Integer.parseInt(bufferedReader.readLine().trim()); 39 | 40 | List arr = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) 41 | .map(Integer::parseInt) 42 | .collect(toList()); 43 | 44 | int result = migratoryBirds(arr); 45 | 46 | bufferedWriter.write(String.valueOf(result)); 47 | bufferedWriter.newLine(); 48 | 49 | bufferedReader.close(); 50 | bufferedWriter.close(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ProblemSolving (General)/AngryProfessor.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class AngryProfessor { 10 | 11 | // Complete the angryProfessor function below. 12 | static String angryProfessor(int k, int[] a) { 13 | int counter = 0; 14 | for(int i=0;i= k){ 19 | return "NO"; 20 | } 21 | } 22 | 23 | return "YES"; 24 | 25 | } 26 | 27 | private static final Scanner scanner = new Scanner(System.in); 28 | 29 | public static void main(String[] args) throws IOException { 30 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 31 | 32 | int t = scanner.nextInt(); 33 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 34 | 35 | for (int tItr = 0; tItr < t; tItr++) { 36 | String[] nk = scanner.nextLine().split(" "); 37 | 38 | int n = Integer.parseInt(nk[0]); 39 | 40 | int k = Integer.parseInt(nk[1]); 41 | 42 | int[] a = new int[n]; 43 | 44 | String[] aItems = scanner.nextLine().split(" "); 45 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 46 | 47 | for (int i = 0; i < n; i++) { 48 | int aItem = Integer.parseInt(aItems[i]); 49 | a[i] = aItem; 50 | } 51 | 52 | String result = angryProfessor(k, a); 53 | 54 | bufferedWriter.write(result); 55 | bufferedWriter.newLine(); 56 | } 57 | 58 | bufferedWriter.close(); 59 | 60 | scanner.close(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /ProblemSolving (General)/Encryption.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Encryption { 10 | 11 | // Complete the encryption function below. 12 | static String encryption(String s) { 13 | String result = s.replaceAll("\\s",""); 14 | int r = (int)Math.floor(Math.sqrt(s.length())); 15 | int c = (int)Math.ceil(Math.sqrt(s.length())); 16 | if(r*c < s.length()){ 17 | r++; 18 | } 19 | int k = 0; 20 | char[][] array = new char[r][c]; 21 | for(int i=0;i s, int d, int m) { 17 | if(s.size() < m){ 18 | return 0; 19 | } 20 | int counter = 0, sum = 0; 21 | for(int i=0;i<=s.size()-m;i++){ 22 | for(int j=i;j s = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) 41 | .map(Integer::parseInt) 42 | .collect(toList()); 43 | 44 | String[] dm = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); 45 | 46 | int d = Integer.parseInt(dm[0]); 47 | 48 | int m = Integer.parseInt(dm[1]); 49 | 50 | int result = birthday(s, d, m); 51 | 52 | bufferedWriter.write(String.valueOf(result)); 53 | bufferedWriter.newLine(); 54 | 55 | bufferedReader.close(); 56 | bufferedWriter.close(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ProblemSolving (General)/GridChallenge.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class GridChallenge { 10 | 11 | // Complete the gridChallenge function below. 12 | static String gridChallenge(String[] grid) { 13 | for(int i=0;i grid[j+1].charAt(i)){ 21 | return "NO"; 22 | } 23 | } 24 | } 25 | return "YES"; 26 | 27 | } 28 | 29 | private static final Scanner scanner = new Scanner(System.in); 30 | 31 | public static void main(String[] args) throws IOException { 32 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 33 | 34 | int t = scanner.nextInt(); 35 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 36 | 37 | for (int tItr = 0; tItr < t; tItr++) { 38 | int n = scanner.nextInt(); 39 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 40 | 41 | String[] grid = new String[n]; 42 | 43 | for (int i = 0; i < n; i++) { 44 | String gridItem = scanner.nextLine(); 45 | grid[i] = gridItem; 46 | } 47 | 48 | String result = gridChallenge(grid); 49 | 50 | bufferedWriter.write(result); 51 | bufferedWriter.newLine(); 52 | } 53 | 54 | bufferedWriter.close(); 55 | 56 | scanner.close(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ProblemSolving/src/solution/JavaAnagrams.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class JavaAnagrams { 4 | 5 | static boolean isAnagram(String a, String b) { 6 | // Complete the function 7 | if(a.length() != b.length()) { 8 | return false; 9 | } 10 | String a1 = a.toLowerCase(); 11 | String b1 = b.toLowerCase(); 12 | char[] arr1 = new char[a.length()]; 13 | char[] arr2 = new char[b.length()]; 14 | for(int i=0;i= 0){ 37 | flag = 0; 38 | } 39 | } 40 | 41 | return result; 42 | 43 | } 44 | 45 | } 46 | 47 | public class CountingValleys { 48 | public static void main(String[] args) throws IOException { 49 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 50 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 51 | 52 | int steps = Integer.parseInt(bufferedReader.readLine().trim()); 53 | 54 | String path = bufferedReader.readLine(); 55 | 56 | int result = Result.countingValleys(steps, path); 57 | 58 | bufferedWriter.write(String.valueOf(result)); 59 | bufferedWriter.newLine(); 60 | 61 | bufferedReader.close(); 62 | bufferedWriter.close(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /ProblemSolving (General)/SherlockAndAnagrams.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class SherlockAndAnagrams { 10 | 11 | // Complete the sherlockAndAnagrams function below. 12 | static int sherlockAndAnagrams(String s) { 13 | int result = 0; 14 | HashMap h = new HashMap(); 15 | for(int i=0;i compareTriplets(List a, List b) { 17 | List l = new ArrayList<>(); 18 | int counter1 = 0, counter2 = 0; 19 | for(int i=0;i b.get(i)){ 21 | counter1++; 22 | }else if(b.get(i) > a.get(i)){ 23 | counter2++; 24 | } 25 | } 26 | l.add(counter1); 27 | l.add(counter2); 28 | return l; 29 | } 30 | 31 | public static void main(String[] args) throws IOException { 32 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 33 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 34 | 35 | List a = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) 36 | .map(Integer::parseInt) 37 | .collect(toList()); 38 | 39 | List b = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) 40 | .map(Integer::parseInt) 41 | .collect(toList()); 42 | 43 | List result = compareTriplets(a, b); 44 | 45 | bufferedWriter.write( 46 | result.stream() 47 | .map(Object::toString) 48 | .collect(joining(" ")) 49 | + "\n" 50 | ); 51 | 52 | bufferedReader.close(); 53 | bufferedWriter.close(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ProblemSolving (General)/BreakingTheRecords.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class BreakingTheRecords { 10 | 11 | // Complete the breakingRecords function below. 12 | static int[] breakingRecords(int[] scores) { 13 | int min = scores[0], max = scores[0] , maxcounter = 0, mincounter = 0; 14 | for(int i=1;i max){ 16 | max = scores[i]; 17 | maxcounter++; 18 | } 19 | if(scores[i] < min){ 20 | min = scores[i]; 21 | mincounter++; 22 | } 23 | } 24 | 25 | int[] array = {maxcounter,mincounter}; 26 | return array; 27 | } 28 | 29 | private static final Scanner scanner = new Scanner(System.in); 30 | 31 | public static void main(String[] args) throws IOException { 32 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 33 | 34 | int n = scanner.nextInt(); 35 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 36 | 37 | int[] scores = new int[n]; 38 | 39 | String[] scoresItems = scanner.nextLine().split(" "); 40 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 41 | 42 | for (int i = 0; i < n; i++) { 43 | int scoresItem = Integer.parseInt(scoresItems[i]); 44 | scores[i] = scoresItem; 45 | } 46 | 47 | int[] result = breakingRecords(scores); 48 | 49 | for (int i = 0; i < result.length; i++) { 50 | bufferedWriter.write(String.valueOf(result[i])); 51 | 52 | if (i != result.length - 1) { 53 | bufferedWriter.write(" "); 54 | } 55 | } 56 | 57 | bufferedWriter.newLine(); 58 | 59 | bufferedWriter.close(); 60 | 61 | scanner.close(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ProblemSolving (General)/ModifiedKaprekarNumbers.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class ModifiedKaprekarNumbers { 10 | 11 | // Complete the kaprekarNumbers function below. 12 | static void kaprekarNumbers(int p, int q) { 13 | int flag = 0; 14 | for(long i=p;i<=q;i++){ 15 | String d = String.valueOf(i); 16 | long squared = i*i; 17 | if(String.valueOf(squared).length() == 2*d.length() || String.valueOf(squared).length() == (2*d.length())-1 ){ 18 | 19 | String s = String.valueOf(squared); 20 | String s1 = s.substring(0,s.length()/2); 21 | String s2 = s.substring(s.length()/2); 22 | long numberl = 0 , numberr = 0;; 23 | if(s1.length() == 0){ 24 | numberl = 0; 25 | }else{ 26 | numberl = Long.parseLong(s1); 27 | } 28 | 29 | if(s2.length() == 0){ 30 | numberr = 0; 31 | }else{ 32 | numberr = Long.parseLong(s2); 33 | } 34 | 35 | if(numberl + numberr == i){ 36 | flag = 1; 37 | System.out.print(i + " "); 38 | } 39 | 40 | } 41 | } 42 | 43 | if(flag == 0){ 44 | System.out.println("INVALID RANGE"); 45 | } 46 | 47 | 48 | } 49 | 50 | private static final Scanner scanner = new Scanner(System.in); 51 | 52 | public static void main(String[] args) { 53 | int p = scanner.nextInt(); 54 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 55 | 56 | int q = scanner.nextInt(); 57 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 58 | 59 | kaprekarNumbers(p, q); 60 | 61 | scanner.close(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ProblemSolving (General)/SequenceEquation.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class SequenceEquation { 10 | 11 | // Complete the permutationEquation function below. 12 | static int[] permutationEquation(int[] p) { 13 | int[] result = new int[p.length]; 14 | HashMap hInside = new HashMap(); 15 | HashMap hOutside = new HashMap(); 16 | int counter = 1; 17 | for(int i=0;i l = new ArrayList<>(); 14 | Arrays.sort(arr); 15 | int min = 1000000000; 16 | for(int i=0;ii).toArray(); 30 | return array; 31 | 32 | } 33 | 34 | private static final Scanner scanner = new Scanner(System.in); 35 | 36 | public static void main(String[] args) throws IOException { 37 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 38 | 39 | int n = scanner.nextInt(); 40 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 41 | 42 | int[] arr = new int[n]; 43 | 44 | String[] arrItems = scanner.nextLine().split(" "); 45 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 46 | 47 | for (int i = 0; i < n; i++) { 48 | int arrItem = Integer.parseInt(arrItems[i]); 49 | arr[i] = arrItem; 50 | } 51 | 52 | int[] result = closestNumbers(arr); 53 | 54 | for (int i = 0; i < result.length; i++) { 55 | bufferedWriter.write(String.valueOf(result[i])); 56 | 57 | if (i != result.length - 1) { 58 | bufferedWriter.write(" "); 59 | } 60 | } 61 | 62 | bufferedWriter.newLine(); 63 | 64 | bufferedWriter.close(); 65 | 66 | scanner.close(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /ProblemSolving (General)/FairRations.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class FairRations { 10 | 11 | // Complete the fairRations function below. 12 | static int fairRations(int[] B) { 13 | int counter = 0; 14 | if(firstOdd(B) == -1){ 15 | return 0; 16 | } 17 | int i = 0; 18 | while(i < B.length-1){ 19 | if(B[i]%2 != 0){ 20 | B[i]++; 21 | B[i+1]++; 22 | counter += 2; 23 | } 24 | i++; 25 | } 26 | if(B[B.length-1]%2 != 0){ 27 | return -1; 28 | } 29 | 30 | return counter; 31 | 32 | } 33 | 34 | static int firstOdd(int[] B){ 35 | for(int i=0;i arr) { 17 | if(arr.size() == 0){ 18 | return "YES"; 19 | } 20 | int[] array = arr.stream().mapToInt(i->i).toArray(); 21 | for(int i=1;i { 44 | try { 45 | int n = Integer.parseInt(bufferedReader.readLine().trim()); 46 | 47 | List arr = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) 48 | .map(Integer::parseInt) 49 | .collect(toList()); 50 | 51 | String result = balancedSums(arr); 52 | 53 | bufferedWriter.write(result); 54 | bufferedWriter.newLine(); 55 | } catch (IOException ex) { 56 | throw new RuntimeException(ex); 57 | } 58 | }); 59 | 60 | bufferedReader.close(); 61 | bufferedWriter.close(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ProblemSolving (General)/DiagonalDifference.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | class Result { 10 | 11 | /* 12 | * Complete the 'diagonalDifference' function below. 13 | * 14 | * The function is expected to return an INTEGER. 15 | * The function accepts 2D_INTEGER_ARRAY arr as parameter. 16 | */ 17 | 18 | public static int diagonalDifference(List> arr) { 19 | // Write your code here 20 | int i =0,j=0,sum1=0,sum2=0; 21 | for(i=0;i> arr = new ArrayList<>(); 45 | 46 | for (int i = 0; i < n; i++) { 47 | String[] arrRowTempItems = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); 48 | 49 | List arrRowItems = new ArrayList<>(); 50 | 51 | for (int j = 0; j < n; j++) { 52 | int arrItem = Integer.parseInt(arrRowTempItems[j]); 53 | arrRowItems.add(arrItem); 54 | } 55 | 56 | arr.add(arrRowItems); 57 | } 58 | 59 | int result = Result.diagonalDifference(arr); 60 | 61 | bufferedWriter.write(String.valueOf(result)); 62 | bufferedWriter.newLine(); 63 | 64 | bufferedReader.close(); 65 | bufferedWriter.close(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ProblemSolving (General)/CircularArrayRotation.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class CircularArrayRotation { 10 | 11 | // Complete the circularArrayRotation function below. 12 | static int[] circularArrayRotation(int[] a, int k, int[] queries) { 13 | int[] array = new int[a.length]; 14 | for(int i=0;i h = new HashMap(); 16 | int counter = 1, min = 0, flag = 0; 17 | Arrays.sort(arr); 18 | if(arr[0] == arr[arr.length-1]){ 19 | return 0; 20 | } 21 | 22 | for(int i=0;i m : h.entrySet()){ 43 | if(m.getValue() > min){ 44 | min = m.getValue(); 45 | } 46 | } 47 | 48 | return arr.length - min; 49 | 50 | } 51 | 52 | private static final Scanner scanner = new Scanner(System.in); 53 | 54 | public static void main(String[] args) throws IOException { 55 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 56 | 57 | int n = scanner.nextInt(); 58 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 59 | 60 | int[] arr = new int[n]; 61 | 62 | String[] arrItems = scanner.nextLine().split(" "); 63 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 64 | 65 | for (int i = 0; i < n; i++) { 66 | int arrItem = Integer.parseInt(arrItems[i]); 67 | arr[i] = arrItem; 68 | } 69 | 70 | int result = equalizeArray(arr); 71 | 72 | bufferedWriter.write(String.valueOf(result)); 73 | bufferedWriter.newLine(); 74 | 75 | bufferedWriter.close(); 76 | 77 | scanner.close(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /ProblemSolving (General)/ACMICPCTeam.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class ACMICPCTeam { 10 | 11 | // Complete the acmTeam function below. 12 | static int[] acmTeam(String[] topic) { 13 | List l = new ArrayList<>(); 14 | int counter = 0, frequency = 0; 15 | for(int i=0;i= 0;i--){ 33 | if(array[i] == array[array.length-1]){ 34 | frequency++; 35 | } 36 | } 37 | return new int[]{array[array.length-1], frequency}; 38 | 39 | } 40 | 41 | private static final Scanner scanner = new Scanner(System.in); 42 | 43 | public static void main(String[] args) throws IOException { 44 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 45 | 46 | String[] nm = scanner.nextLine().split(" "); 47 | 48 | int n = Integer.parseInt(nm[0]); 49 | 50 | int m = Integer.parseInt(nm[1]); 51 | 52 | String[] topic = new String[n]; 53 | 54 | for (int i = 0; i < n; i++) { 55 | String topicItem = scanner.nextLine(); 56 | topic[i] = topicItem; 57 | } 58 | 59 | int[] result = acmTeam(topic); 60 | 61 | for (int i = 0; i < result.length; i++) { 62 | bufferedWriter.write(String.valueOf(result[i])); 63 | 64 | if (i != result.length - 1) { 65 | bufferedWriter.write("\n"); 66 | } 67 | } 68 | 69 | bufferedWriter.newLine(); 70 | 71 | bufferedWriter.close(); 72 | 73 | scanner.close(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /ProblemSolving (General)/AppleAndOrange.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class AppleAndOrange { 10 | 11 | // Complete the countApplesAndOranges function below. 12 | static void countApplesAndOranges(int s, int t, int a, int b, int[] apples, int[] oranges) { 13 | int countera = 0, countero = 0; 14 | for(int i=0;i= s && a + apples[i] <= t){ 16 | countera++; 17 | } 18 | } 19 | 20 | for(int i=0;i= s && b + oranges[i] <= t){ 22 | countero++; 23 | } 24 | } 25 | 26 | System.out.println(countera); 27 | System.out.println(countero); 28 | } 29 | 30 | private static final Scanner scanner = new Scanner(System.in); 31 | 32 | public static void main(String[] args) { 33 | String[] st = scanner.nextLine().split(" "); 34 | 35 | int s = Integer.parseInt(st[0]); 36 | 37 | int t = Integer.parseInt(st[1]); 38 | 39 | String[] ab = scanner.nextLine().split(" "); 40 | 41 | int a = Integer.parseInt(ab[0]); 42 | 43 | int b = Integer.parseInt(ab[1]); 44 | 45 | String[] mn = scanner.nextLine().split(" "); 46 | 47 | int m = Integer.parseInt(mn[0]); 48 | 49 | int n = Integer.parseInt(mn[1]); 50 | 51 | int[] apples = new int[m]; 52 | 53 | String[] applesItems = scanner.nextLine().split(" "); 54 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 55 | 56 | for (int i = 0; i < m; i++) { 57 | int applesItem = Integer.parseInt(applesItems[i]); 58 | apples[i] = applesItem; 59 | } 60 | 61 | int[] oranges = new int[n]; 62 | 63 | String[] orangesItems = scanner.nextLine().split(" "); 64 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 65 | 66 | for (int i = 0; i < n; i++) { 67 | int orangesItem = Integer.parseInt(orangesItems[i]); 68 | oranges[i] = orangesItem; 69 | } 70 | 71 | countApplesAndOranges(s, t, a, b, apples, oranges); 72 | 73 | scanner.close(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /ProblemSolving (General)/FlatlandSpaceStations.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class FlatlandSpaceStations { 10 | 11 | // Complete the flatlandSpaceStations function below. 12 | static int flatlandSpaceStations(int n, int[] stations) { 13 | Arrays.sort(stations); 14 | int first = stations[0]; 15 | int max = Math.max(first, n-stations[stations.length - 1]-1); 16 | for (int i=0;i< stations.length-1;i++) { 17 | max = Math.max((stations[i + 1] - stations[i]) / 2, max); 18 | } 19 | return max; 20 | } 21 | 22 | static int bigger(int element ,int[] stations){ 23 | Arrays.sort(stations); 24 | for(int i=0;i element){ 26 | return stations[i]; 27 | } 28 | } 29 | return element; 30 | } 31 | 32 | static int smaller(int element ,int[] stations){ 33 | Arrays.sort(stations); 34 | for(int i=stations.length-1;i >= 0;i--){ 35 | if(stations[i] < element){ 36 | return stations[i]; 37 | } 38 | } 39 | return element; 40 | } 41 | 42 | private static final Scanner scanner = new Scanner(System.in); 43 | 44 | public static void main(String[] args) throws IOException { 45 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 46 | 47 | String[] nm = scanner.nextLine().split(" "); 48 | 49 | int n = Integer.parseInt(nm[0]); 50 | 51 | int m = Integer.parseInt(nm[1]); 52 | 53 | int[] c = new int[m]; 54 | 55 | String[] cItems = scanner.nextLine().split(" "); 56 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 57 | 58 | for (int i = 0; i < m; i++) { 59 | int cItem = Integer.parseInt(cItems[i]); 60 | c[i] = cItem; 61 | } 62 | 63 | int result = flatlandSpaceStations(n, c); 64 | 65 | bufferedWriter.write(String.valueOf(result)); 66 | bufferedWriter.newLine(); 67 | 68 | bufferedWriter.close(); 69 | 70 | scanner.close(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /ProblemSolving (General)/StrongPassword.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class StrongPassword { 10 | 11 | // Complete the minimumNumber function below. 12 | public static int minimumNumber(int n, String password) { 13 | int counter = 0, check1 = 0, check2 = 0, check3 = 0, check4 = 0, check5 = 0; 14 | if(n == 0){ 15 | return 6; 16 | } 17 | 18 | for(int i=0;i= 6) { 35 | return counter; 36 | }else { 37 | return (counter + (6 - (counter+n))); 38 | } 39 | 40 | 41 | } 42 | 43 | private static final Scanner scanner = new Scanner(System.in); 44 | 45 | public static void main(String[] args) throws IOException { 46 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 47 | 48 | int n = scanner.nextInt(); 49 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 50 | 51 | String password = scanner.nextLine(); 52 | 53 | int answer = minimumNumber(n, password); 54 | 55 | bufferedWriter.write(String.valueOf(answer)); 56 | bufferedWriter.newLine(); 57 | 58 | bufferedWriter.close(); 59 | 60 | scanner.close(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /ProblemSolving (General)/GradingStudents.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.function.*; 8 | import java.util.regex.*; 9 | import java.util.stream.*; 10 | import static java.util.stream.Collectors.joining; 11 | import static java.util.stream.Collectors.toList; 12 | 13 | class Result { 14 | 15 | /* 16 | * Complete the 'gradingStudents' function below. 17 | * 18 | * The function is expected to return an INTEGER_ARRAY. 19 | * The function accepts INTEGER_ARRAY grades as parameter. 20 | */ 21 | 22 | public static List gradingStudents(List grades) { 23 | List l = new ArrayList<>(); 24 | for(int i=0;i grades = IntStream.range(0, gradesCount).mapToObj(i -> { 53 | try { 54 | return bufferedReader.readLine().replaceAll("\\s+$", ""); 55 | } catch (IOException ex) { 56 | throw new RuntimeException(ex); 57 | } 58 | }) 59 | .map(String::trim) 60 | .map(Integer::parseInt) 61 | .collect(toList()); 62 | 63 | List result = Result.gradingStudents(grades); 64 | 65 | bufferedWriter.write( 66 | result.stream() 67 | .map(Object::toString) 68 | .collect(joining("\n")) 69 | + "\n" 70 | ); 71 | 72 | bufferedReader.close(); 73 | bufferedWriter.close(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /ProblemSolving (General)/CutTheSticks.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class CutTheSticks { 10 | 11 | // Complete the cutTheSticks function below. 12 | static int[] cutTheSticks(int[] arr) { 13 | List l = new ArrayList<>(); 14 | Arrays.sort(arr); 15 | l.add(arr.length); 16 | while(arr[arr.length-1] > 0){ 17 | int min = NonZeroMin(arr); 18 | for(int j=0;j 0){ 24 | counter++; 25 | } 26 | } 27 | if(counter > 0){ 28 | l.add(counter); 29 | } 30 | } 31 | int result[] = new int[l.size()]; 32 | for(int i=0;i 0 && arr[i] < min){ 43 | min = arr[i]; 44 | } 45 | } 46 | return min; 47 | } 48 | 49 | 50 | private static final Scanner scanner = new Scanner(System.in); 51 | 52 | public static void main(String[] args) throws IOException { 53 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 54 | 55 | int n = scanner.nextInt(); 56 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 57 | 58 | int[] arr = new int[n]; 59 | 60 | String[] arrItems = scanner.nextLine().split(" "); 61 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 62 | 63 | for (int i = 0; i < n; i++) { 64 | int arrItem = Integer.parseInt(arrItems[i]); 65 | arr[i] = arrItem; 66 | } 67 | 68 | int[] result = cutTheSticks(arr); 69 | 70 | for (int i = 0; i < result.length; i++) { 71 | bufferedWriter.write(String.valueOf(result[i])); 72 | 73 | if (i != result.length - 1) { 74 | bufferedWriter.write("\n"); 75 | } 76 | } 77 | 78 | bufferedWriter.newLine(); 79 | 80 | bufferedWriter.close(); 81 | 82 | scanner.close(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /ProblemSolving (General)/ServiceLane.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class ServiceLane { 10 | 11 | // Complete the serviceLane function below. 12 | static int[] serviceLane(int[] width, int[][] cases) { 13 | List l = new ArrayList<>(); 14 | int min = 9999999; 15 | for(int i=0;i l = new ArrayList<>(); 14 | int size = 0, result = 0; 15 | for(int i=0;i= 0;i--){ 33 | if(k > 0){ 34 | result += luckArray[i]; 35 | k--; 36 | }else{ 37 | result -= luckArray[i]; 38 | } 39 | } 40 | 41 | return result; 42 | 43 | } 44 | 45 | private static final Scanner scanner = new Scanner(System.in); 46 | 47 | public static void main(String[] args) throws IOException { 48 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 49 | 50 | String[] nk = scanner.nextLine().split(" "); 51 | 52 | int n = Integer.parseInt(nk[0]); 53 | 54 | int k = Integer.parseInt(nk[1]); 55 | 56 | int[][] contests = new int[n][2]; 57 | 58 | for (int i = 0; i < n; i++) { 59 | String[] contestsRowItems = scanner.nextLine().split(" "); 60 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 61 | 62 | for (int j = 0; j < 2; j++) { 63 | int contestsItem = Integer.parseInt(contestsRowItems[j]); 64 | contests[i][j] = contestsItem; 65 | } 66 | } 67 | 68 | int result = luckBalance(k, contests); 69 | 70 | bufferedWriter.write(String.valueOf(result)); 71 | bufferedWriter.newLine(); 72 | 73 | bufferedWriter.close(); 74 | 75 | scanner.close(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /ProblemSolving (General)/WeightedUniformStrings.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class WeightedUniformStrings { 10 | 11 | // Complete the weightedUniformStrings function below. 12 | static String[] weightedUniformStrings(String s, int[] queries) { 13 | HashSet theWeights = new HashSet<>(); 14 | String[] result = new String[queries.length]; 15 | char[] cArray = s.toCharArray(); 16 | int Weight = 0; 17 | char prev = ' '; 18 | for(int i=0;i= k){ 24 | flag = 1; 25 | B[i] = -2222222; 26 | break; 27 | } 28 | } 29 | if(flag == 0){ 30 | return "NO"; 31 | } 32 | flag = 0; 33 | } 34 | 35 | return "YES"; 36 | } 37 | 38 | private static final Scanner scanner = new Scanner(System.in); 39 | 40 | public static void main(String[] args) throws IOException { 41 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 42 | 43 | int q = scanner.nextInt(); 44 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 45 | 46 | for (int qItr = 0; qItr < q; qItr++) { 47 | String[] nk = scanner.nextLine().split(" "); 48 | 49 | int n = Integer.parseInt(nk[0]); 50 | 51 | int k = Integer.parseInt(nk[1]); 52 | 53 | int[] A = new int[n]; 54 | 55 | String[] AItems = scanner.nextLine().split(" "); 56 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 57 | 58 | for (int i = 0; i < n; i++) { 59 | int AItem = Integer.parseInt(AItems[i]); 60 | A[i] = AItem; 61 | } 62 | 63 | int[] B = new int[n]; 64 | 65 | String[] BItems = scanner.nextLine().split(" "); 66 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 67 | 68 | for (int i = 0; i < n; i++) { 69 | int BItem = Integer.parseInt(BItems[i]); 70 | B[i] = BItem; 71 | } 72 | 73 | String result = twoArrays(k, A, B); 74 | 75 | bufferedWriter.write(result); 76 | bufferedWriter.newLine(); 77 | } 78 | 79 | bufferedWriter.close(); 80 | 81 | scanner.close(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /ProblemSolving (General)/ElectronicsShop.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.text.*; 4 | import java.util.*; 5 | import java.util.regex.*; 6 | 7 | public class ElectronicsShop { 8 | 9 | /* 10 | * Complete the getMoneySpent function below. 11 | */ 12 | static int getMoneySpent(int[] keyboards, int[] drives, int b) { 13 | Arrays.sort(keyboards); 14 | Arrays.sort(drives); 15 | if(drives[0] + keyboards[0] > b){ 16 | return -1; 17 | } 18 | int diference = 100000000; 19 | for(int i=keyboards.length-1;i >= 0;i--){ 20 | for(int j=drives.length-1;j >= 0;j--){ 21 | if((b - (keyboards[i]+drives[j])) < diference && (keyboards[i]+drives[j]) <= b){ 22 | diference = (b - (keyboards[i]+drives[j])); 23 | } 24 | } 25 | } 26 | 27 | return b - diference; 28 | 29 | } 30 | 31 | private static final Scanner scanner = new Scanner(System.in); 32 | 33 | public static void main(String[] args) throws IOException { 34 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 35 | 36 | String[] bnm = scanner.nextLine().split(" "); 37 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])*"); 38 | 39 | int b = Integer.parseInt(bnm[0]); 40 | 41 | int n = Integer.parseInt(bnm[1]); 42 | 43 | int m = Integer.parseInt(bnm[2]); 44 | 45 | int[] keyboards = new int[n]; 46 | 47 | String[] keyboardsItems = scanner.nextLine().split(" "); 48 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])*"); 49 | 50 | for (int keyboardsItr = 0; keyboardsItr < n; keyboardsItr++) { 51 | int keyboardsItem = Integer.parseInt(keyboardsItems[keyboardsItr]); 52 | keyboards[keyboardsItr] = keyboardsItem; 53 | } 54 | 55 | int[] drives = new int[m]; 56 | 57 | String[] drivesItems = scanner.nextLine().split(" "); 58 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])*"); 59 | 60 | for (int drivesItr = 0; drivesItr < m; drivesItr++) { 61 | int drivesItem = Integer.parseInt(drivesItems[drivesItr]); 62 | drives[drivesItr] = drivesItem; 63 | } 64 | 65 | /* 66 | * The maximum amount of money she can spend on a keyboard and USB drive, or -1 if she can't purchase both items 67 | */ 68 | 69 | int moneySpent = getMoneySpent(keyboards, drives, b); 70 | 71 | bufferedWriter.write(String.valueOf(moneySpent)); 72 | bufferedWriter.newLine(); 73 | 74 | bufferedWriter.close(); 75 | 76 | scanner.close(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /ProblemSolving (General)/JimAndTheOrders.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class JimAndTheOrders { 10 | 11 | // Complete the jimOrders function below. 12 | static int[] jimOrders(int[][] orders) { 13 | int[] time = new int[orders.length]; 14 | HashMap h = new HashMap(); 15 | for(int i=0;i sortedValues = new ArrayList(h.values()); 31 | Collections.sort(sortedValues); 32 | int[] theFinal = new int[time.length]; 33 | for(int i=0;i entry : h.entrySet()){ 35 | if(sortedValues.get(i) == entry.getValue()){ 36 | theFinal[i] = entry.getKey(); 37 | h.put(entry.getKey(),-1); 38 | } 39 | } 40 | 41 | } 42 | 43 | return theFinal; 44 | 45 | } 46 | 47 | private static final Scanner scanner = new Scanner(System.in); 48 | 49 | public static void main(String[] args) throws IOException { 50 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 51 | 52 | int n = scanner.nextInt(); 53 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 54 | 55 | int[][] orders = new int[n][2]; 56 | 57 | for (int i = 0; i < n; i++) { 58 | String[] ordersRowItems = scanner.nextLine().split(" "); 59 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 60 | 61 | for (int j = 0; j < 2; j++) { 62 | int ordersItem = Integer.parseInt(ordersRowItems[j]); 63 | orders[i][j] = ordersItem; 64 | } 65 | } 66 | 67 | int[] result = jimOrders(orders); 68 | 69 | for (int i = 0; i < result.length; i++) { 70 | bufferedWriter.write(String.valueOf(result[i])); 71 | 72 | if (i != result.length - 1) { 73 | bufferedWriter.write(" "); 74 | } 75 | } 76 | 77 | bufferedWriter.newLine(); 78 | 79 | bufferedWriter.close(); 80 | 81 | scanner.close(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /ProblemSolving (General)/BetweenTwoSets.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.function.*; 8 | import java.util.regex.*; 9 | import java.util.stream.*; 10 | import static java.util.stream.Collectors.joining; 11 | import static java.util.stream.Collectors.toList; 12 | 13 | class Result { 14 | 15 | /* 16 | * Complete the 'getTotalX' function below. 17 | * 18 | * The function is expected to return an INTEGER. 19 | * The function accepts following parameters: 20 | * 1. INTEGER_ARRAY a 21 | * 2. INTEGER_ARRAY b 22 | */ 23 | 24 | public static int getTotalX(List a, List b) { 25 | // Write your code here 26 | int[] array1 = new int[a.size()]; 27 | int[] array2 = new int[b.size()]; 28 | for(int i=0;i arr = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) 75 | .map(Integer::parseInt) 76 | .collect(toList()); 77 | 78 | List brr = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) 79 | .map(Integer::parseInt) 80 | .collect(toList()); 81 | 82 | int total = Result.getTotalX(arr, brr); 83 | 84 | bufferedWriter.write(String.valueOf(total)); 85 | bufferedWriter.newLine(); 86 | 87 | bufferedReader.close(); 88 | bufferedWriter.close(); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /ProblemSolving (General)/MissingNumbers.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class MissingNumbers { 10 | 11 | // Complete the missingNumbers function below. 12 | static int[] missingNumbers(int[] missed, int[] original) { 13 | HashMap hOriginal = new HashMap(); 14 | HashMap hMissed = new HashMap(); 15 | List l = new ArrayList<>(); 16 | for(int i=0;i hMissed.get(element)){ 34 | l.add(element); 35 | } 36 | }else{ 37 | l.add(element); 38 | } 39 | } 40 | 41 | int[] result = new int[l.size()]; 42 | for(int i=0;i