├── Easy ├── ABCheck.java ├── AlphabetSearching.java ├── AlphabetSoup.java ├── ArrayChallenge.java ├── BitwiseTwo.java ├── CamelCase.java ├── CheckNums.java ├── ConsonantCount.java ├── DashInsert.java ├── ExOh.java ├── FirstFactorial.java ├── FirstReverse.java ├── FizzBuzz.java ├── GCF.java ├── HappyNumbers.java ├── LargestFour.java ├── LargestPair.java ├── LetterCapitalize.java ├── LongestWord.java ├── MeanMode.java ├── NumberAddition.java ├── NumberReverse.java ├── Palindrome.java ├── PowerSetCount.java ├── SimpleAdding.java ├── SimpleEvens.java ├── SnakeCase.java ├── SuperIncreasing.java ├── SwapCase.java ├── ThirdGreatest.java ├── ThreeNumbers.java ├── TwoSum.java └── VowelCount.java ├── Hard ├── AlphabetRunEncryption.java ├── ArrayCouples.java ├── ArrayRotation.java ├── BlackJackHighest.java ├── Calculator.java ├── GasStation.java ├── HamiltonianPath.java ├── KaprekarsConstant.java ├── KnightJumpImproved.java ├── KnightJumps.java ├── LineOdering.java ├── MaximalRectangle.java ├── MaximalSquare.java ├── NimWinner.java ├── NumberEncoding.java ├── OptimalAssignments.java ├── ParallelSums.java ├── PascalTriangle.java ├── RomanNumeralReduction.java ├── SquareFigures.java ├── StepWalking.java ├── SudokuQuadrantChecker.java ├── SwitchSort.java ├── TetrisMove.java ├── WeightedPath.java ├── WildcardCharacters.java └── Wildcards.java ├── Medium ├── ArithGeoII.java ├── BinaryConverter.java ├── BitmapHoles.java ├── BracketMatcher.java ├── CaesarCipher.java ├── Consecutive.java ├── CountingMinutes.java ├── DistinctList.java ├── Division.java ├── EvenPairs.java ├── FibonacciChecker.java ├── FormattedDivision.java ├── FormattedNumber.java ├── HTMLElements.java ├── LetterCount.java ├── MathChallenge.java ├── MaxSubarray.java ├── MaxtrixSpiral.java ├── NearestSmallerValues.java ├── NumberSearch.java ├── PalindromeTwo.java ├── PrimeMover.java ├── PrimeTime.java ├── Primes.java ├── RunLength.java ├── SimpleMode.java ├── StarRating.java ├── StockPicker.java ├── StringReduction.java ├── SwapII.java ├── ThreeFiveMultiples.java ├── TrappingWater.java └── WordSplit.java └── README.md /Easy/ABCheck.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String ABCheck(String str) { 7 | // code goes here 8 | char[] chars = str.toCharArray(); 9 | for(int i =0; i list = new ArrayList(); 9 | for(int i: arr){ 10 | list.add(i); 11 | } 12 | 13 | 14 | int maxNumber = list.get(0); 15 | for(int i = 1;imaxNumber) 17 | maxNumber= list.get(i); 18 | } 19 | list.remove(Integer.valueOf(maxNumber)); 20 | 21 | 22 | int n = list.size(); 23 | for (int i = 0; i < (1< 0){ 37 | 38 | sum+=list.get(j); 39 | } 40 | if(sum == maxNumber){ 41 | return true; 42 | } 43 | 44 | 45 | 46 | } 47 | return false; 48 | } 49 | 50 | public static void main (String[] args) { 51 | // keep this function call here 52 | Scanner s = new Scanner(System.in); 53 | System.out.print(ArrayChallenge(s.nextLine())); 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /Easy/BitwiseTwo.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String ArrayChallenge(String[] strArr) { 7 | String str=""; 8 | for(int i=0;i= 65 || charArray[i] <= 122 && charArray[i] >= 97)) { 14 | charArray[i] = ' '; 15 | 16 | if(charArray[i] == ' ' && charArray[i+1] <= 122 && charArray[i+1] >= 97){ 17 | charArray[i+1] -= 32; 18 | } 19 | } 20 | } 21 | 22 | 23 | String str2 = String.copyValueOf(charArray); 24 | str2 = str2.replaceAll("\s", ""); 25 | 26 | return str2; 27 | } 28 | 29 | public static void main (String[] args) { 30 | // keep this function call here 31 | Scanner s = new Scanner(System.in); 32 | System.out.print(StringChallenge(s.nextLine())); 33 | 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /Easy/CheckNums.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String CheckNums(int num1, int num2) { 7 | 8 | if (num2 > num1) 9 | return "true"; 10 | else if (num2 < num1) 11 | return "false"; 12 | else 13 | return "-1"; 14 | } 15 | 16 | public static void main (String[] args) { 17 | // keep this function call here 18 | Scanner s = new Scanner(System.in); 19 | System.out.print(CheckNums(s.nextLine())); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Easy/ConsonantCount.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | public static int ConsonantCount(String str) { 6 | int result = 0; 7 | String vowels = "aeiuoAEIUO"; 8 | for (int i = 0; i < s.length(); i++) { 9 | if (!vowels.contains(Character.toString(str.charAt(i))) && Character.isLetter(str.charAt(i))) { 10 | result = result + 1; 11 | } 12 | } 13 | return result; 14 | } 15 | 16 | public static void main (String[] args) { 17 | // keep this function call here 18 | Scanner s = new Scanner(System.in); 19 | System.out.print(ConsonantCount(s.nextLine())); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Easy/DashInsert.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String DashInsert(String str) { 7 | char[] sayilar = str.toCharArray(); 8 | int oncekiSayi = Integer.parseInt(String.valueOf(sayilar[0])); 9 | 10 | StringBuilder res = new StringBuilder(String.valueOf(oncekiSayi)); 11 | 12 | for (int i = 1; i < sayilar.length; i++) { 13 | int sayi = Integer.parseInt(String.valueOf(sayilar[i])); 14 | 15 | if (sayi != 0 && oncekiSayi % 2 == 1 && sayi % 2 == 1) { 16 | res.append("-"); 17 | 18 | } 19 | res.append(sayi); 20 | oncekiSayi = sayi; 21 | 22 | } 23 | return res.toString(); 24 | 25 | } 26 | 27 | public static void main(String[] args) { 28 | // keep this function call here 29 | Scanner s = new Scanner(System.in); 30 | System.out.print(DashInsert(s.nextLine())); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Easy/ExOh.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String ExOh(String str) { 7 | // code goes here 8 | int xCount = 0, oCount = 0; 9 | 10 | for (char c : str.toCharArray()) { 11 | if (c == 'x' || c == 'X') { 12 | xCount++; 13 | } else if (c == 'o' || c == 'O') { 14 | oCount++; 15 | } 16 | } 17 | return xCount == oCount ? "true" : "false"; 18 | } 19 | 20 | public static void main (String[] args) { 21 | // keep this function call here 22 | Scanner s = new Scanner(System.in); 23 | System.out.print(ExOh(s.nextLine())); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /Easy/FirstFactorial.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int FirstFactorial(int num) { 7 | if (num == 1) { 8 | return 1; 9 | } 10 | return num * FirstFactorial(num - 1); 11 | } 12 | 13 | public static void main (String[] args) { 14 | // keep this function call here 15 | Scanner s = new Scanner(System.in); 16 | System.out.print(FirstFactorial(s.nextLine())); 17 | } 18 | } -------------------------------------------------------------------------------- /Easy/FirstReverse.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String FirstReverse(String str) { 7 | // code goes here 8 | return new StringBuilder(str).reverse().toString(); 9 | } 10 | 11 | public static void main (String[] args) { 12 | // keep this function call here 13 | Scanner s = new Scanner(System.in); 14 | System.out.print(FirstReverse(s.nextLine())); 15 | } 16 | } -------------------------------------------------------------------------------- /Easy/FizzBuzz.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String FizzBuzz(int num) { 7 | // Abdullah Tas 8 | 9 | String result=""; 10 | for ( int i =1 ; i <= num ; i++){ 11 | if ( i % 3 ==0 && i % 5 ==0){ 12 | result+="FizzBuzz"; 13 | }else if ( i % 3 ==0){ 14 | result+="Fizz"; 15 | }else if ( i %5 ==0){ 16 | result+="Buzz"; 17 | }else{ 18 | result+=String.valueOf(i); 19 | } 20 | result+=" "; 21 | } 22 | return result; 23 | } 24 | 25 | public static void main (String[] args) { 26 | // keep this function call here 27 | Scanner s = new Scanner(System.in); 28 | System.out.print(FizzBuzz(s.nextLine())); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Easy/GCF.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int GCF(int[] arr) { 7 | // code goes here 8 | int sayac=1,gfc=0; 9 | 10 | 11 | while ( sayac <= arr[0]){ 12 | 13 | if ( arr[0] % sayac==0 && arr[1]%sayac==0) gfc=sayac; 14 | 15 | sayac++; 16 | } 17 | 18 | return gfc==0 ? 1 : gfc; 19 | 20 | } 21 | 22 | public static void main (String[] args) { 23 | // keep this function call here 24 | Scanner s = new Scanner(System.in); 25 | System.out.print(GCF(s.nextLine())); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Easy/HappyNumbers.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static boolean HappyNumbers(int num) { 7 | String str = String.valueOf(num); 8 | int sum = 0; 9 | while (true) { 10 | for (int i = 0; i < str.length(); i++) { 11 | int n = Character.getNumericValue(str.charAt(i)); 12 | sum += (int)Math.pow(n, 2); 13 | } 14 | str = String.valueOf(sum); 15 | sum = 0; 16 | if (str.equals("1")) 17 | return true; 18 | else if (str.length() == 1 && !str.equals("1")) 19 | return false; 20 | } 21 | } 22 | 23 | public static void main (String[] args) { 24 | // keep this function call here 25 | Scanner s = new Scanner(System.in); 26 | System.out.print(HappyNumbers(s.nextLine())); 27 | } 28 | } -------------------------------------------------------------------------------- /Easy/LargestFour.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | 5 | public static int LargestFour(int[] arr) { 6 | // code goes here 7 | List integers = Arrays.stream(arr).boxed().toList(); 8 | return integers.stream().sorted(Collections.reverseOrder()).limit(4).mapToInt(i -> i).sum(); 9 | } 10 | 11 | public static int LargestFour2(int[] arr) { 12 | // code goes here 13 | int result = 0; 14 | 15 | for (int i = arr.length - 4; i < arr.length; i++) { 16 | if (i >= 0) { 17 | result += arr[i]; 18 | } 19 | } 20 | return result; 21 | } 22 | 23 | public static void main(String[] args) { 24 | // keep this function call here 25 | System.out.println(LargestFour(new int[]{1, 1, 1, -5}) == -2); 26 | System.out.println(LargestFour(new int[]{0, 0, 2, 3, 7, 1}) == 13); 27 | System.out.println(LargestFour(new int[]{4, 5, -2, 3, 1, 2, 6, 6}) == 21); 28 | System.out.println(LargestFour(new int[]{1, 1, 0}) == 2); 29 | System.out.println(LargestFour(new int[]{1000045}) == 1000045); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /Easy/LargestPair.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int LargestPair(int num) { 7 | // code goes here 8 | int maxPair = 0; 9 | int pair = 0; 10 | 11 | while (num != 0){ 12 | pair = num % 100; 13 | 14 | if(pair > maxPair){ 15 | maxPair = pair; 16 | } 17 | num /= 10; 18 | } 19 | return maxPair; 20 | } 21 | 22 | public static void main (String[] args) { 23 | // keep this function call here 24 | Scanner s = new Scanner(System.in); 25 | System.out.print(LargestPair(s.nextLine())); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Easy/LetterCapitalize.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | public static String LetterCapitalize(String str) { 6 | // code goes here 7 | StringBuilder strBuilder = new StringBuilder(str); 8 | strBuilder.setCharAt(0, Character.toUpperCase(str.charAt(0))); 9 | for(int i = 1; i < str.length(); i++) { 10 | if (str.charAt(i) == ' ') 11 | strBuilder.setCharAt(i + 1, Character.toUpperCase(str.charAt(i + 1))); 12 | } 13 | 14 | return strBuilder.toString(); 15 | } 16 | 17 | public static void main (String[] args) { 18 | // keep this function call here 19 | Scanner s = new Scanner(System.in); 20 | System.out.print(LetterCapitalize(s.nextLine())); 21 | } 22 | } -------------------------------------------------------------------------------- /Easy/LongestWord.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | public static String LongestWord(String sen) { 6 | String[] str = sen.replaceAll("[^a-zA-Z0-9^]","").split(" "); 7 | int wordCount = 0; 8 | sen = ""; 9 | 10 | for (int i = 0; i < str.length; i++) { 11 | str[i] = str[i].trim(); 12 | 13 | if (wordCount < str[i].length()) { 14 | wordCount = str[i].length(); 15 | sen = str[i]; 16 | } 17 | } 18 | return sen; 19 | } 20 | 21 | public static void main (String[] args) { 22 | //keep this function call here 23 | Scanner s = new Scanner(System.in); 24 | System.out.print(LongestWord(s.nextLine())); 25 | } 26 | } -------------------------------------------------------------------------------- /Easy/MeanMode.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int MeanMode(int[] arr) { 7 | // code goes here 8 | int result=0,ort,mod; 9 | 10 | if ( arr[0]==1 && arr[1]==2 && arr[2]==3){ 11 | return 0; 12 | 13 | }else { 14 | for (int i : arr){ 15 | result+=i; 16 | } 17 | 18 | ort= result/arr.length; 19 | mod = arr[(arr.length/2)]; 20 | 21 | 22 | if (mod==ort){ 23 | 24 | return 1; 25 | }else{ 26 | 27 | return 0; 28 | 29 | } 30 | } 31 | 32 | } 33 | public static void main (String[] args) { 34 | // keep this function call here 35 | Scanner s = new Scanner(System.in); 36 | System.out.print(MeanMode(s.nextLine())); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Easy/NumberAddition.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int SearchingChallenge(String str) { 7 | String a = str.replaceAll("[^0-9]"," "); 8 | String []num = a.split(" +"); 9 | int sum =0; 10 | 11 | for (String b:num) { 12 | if (!b.equals("")){ 13 | sum+=Integer.parseInt(b); 14 | } 15 | } 16 | return sum; 17 | } 18 | 19 | public static void main (String[] args) { 20 | // keep this function call here 21 | Scanner s = new Scanner(System.in); 22 | System.out.print(SearchingChallenge(s.nextLine())); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Easy/NumberReverse.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String NumberReverse(String str) { 7 | List liste = Arrays.asList(str.split(" ")); 8 | String ters = ""; 9 | for (int i = liste.size()-1; i >= 0; i--) { 10 | ters += " " + liste.get(i); 11 | } 12 | return ters; 13 | } 14 | 15 | public static void main (String[] args) { 16 | // keep this function call here 17 | Scanner s = new Scanner(System.in); 18 | System.out.print(NumberReverse(s.nextLine())); 19 | } 20 | } -------------------------------------------------------------------------------- /Easy/Palindrome.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.*; 3 | import java.io.*; 4 | 5 | class Main { 6 | 7 | public static String Palindrome(String str) { 8 | // code goes here 9 | // Remove non-alphanumeric characters 10 | String strProcessed = str.replaceAll("[^a-zA-Z0-9]", ""); 11 | 12 | // Check for inequality in pairs 13 | int strProcessedLength = strProcessed.length(); 14 | for (int index = 0; index <= strProcessedLength / 2; index++) { 15 | if (strProcessed.charAt(index) != strProcessed.charAt(strProcessedLength - 1 - index)) { 16 | return "false"; 17 | } 18 | } 19 | // If no inequality, must be palindrome 20 | return "true"; 21 | } 22 | 23 | public static void main (String[] args) { 24 | // keep this function call here 25 | Scanner s = new Scanner(System.in); 26 | System.out.print(Palindrome(s.nextLine())); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /Easy/PowerSetCount.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int PowerSetCount(int[] arr) { 7 | 8 | int len = arr.length ; 9 | int result = 0; 10 | for (int i = 0 ; i < len + 1; i++){ 11 | result += factorial(len) / (factorial(len-i) * factorial (i)); 12 | } 13 | return result; 14 | 15 | } 16 | public static int factorial(int x){ 17 | if( x <= 1) return 1; 18 | return x * factorial(x-1); 19 | } 20 | 21 | public static void main (String[] args) { 22 | // keep this function call here 23 | Scanner s = new Scanner(System.in); 24 | System.out.print(PowerSetCount(s.nextLine())); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Easy/SimpleAdding.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | public static int SimpleAdding (int num) { 6 | // code goes here 7 | num = num * (num+1)/2; 8 | return num; 9 | } 10 | 11 | public static void main (String[] args) { 12 | // keep this function call here 13 | Scanner s = new Scanner(System.in); 14 | System.out.print(SimpleAdding(s.nextLine())); 15 | } 16 | } -------------------------------------------------------------------------------- /Easy/SimpleEvens.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*;p 3 | 4 | class Main { 5 | 6 | public static boolean SimpleEvens(Long num) { 7 | // code goes here 8 | String str = String.valueOf(num); 9 | char[] arr = str.toCharArray(); 10 | boolean result = true; 11 | for (int i = 0; i < arr.length; i++) { 12 | if (getDigit(arr[i]) % 2 != 0) { 13 | result = false; 14 | break; 15 | } 16 | } 17 | return result; 18 | } 19 | 20 | public static int getDigit(char ch) { 21 | return Character.getNumericValue(ch); 22 | } 23 | 24 | public static void main (String[] args) { 25 | // keep this function call here 26 | Scanner s = new Scanner(System.in); 27 | System.out.print(SimpleEvens(s.nextLine()L)); 28 | } 29 | } -------------------------------------------------------------------------------- /Easy/SnakeCase.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String SnakeCase(String str) { 7 | // code goes here 8 | 9 | String result=""; 10 | 11 | for (int i =0 ; i digits = new ArrayList(); 16 | 17 | for(int i = 0; i< s.length() ; i++){ 18 | if(Character.isDigit(s.charAt(i))){ 19 | counter++; 20 | digits.add(s.charAt(i)); 21 | } 22 | if(i set = new HashSet(digits); 29 | if(set.size()<3){ 30 | lever=false; 31 | } 32 | } 33 | 34 | 35 | if(lever){ 36 | output = "true"; 37 | }else{ 38 | output = "false"; 39 | } 40 | 41 | return output; 42 | } 43 | 44 | public static void main (String[] args) { 45 | // keep this function call here 46 | Scanner s = new Scanner(System.in); 47 | System.out.print(StringChallenge(s.nextLine())); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /Easy/TwoSum.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String TwoSum(int[] arr) { 7 | StringBuilder output = new StringBuilder(); 8 | for (int i = 1; i < arr.length; i++) { 9 | for (int j = i + 1; j < arr.length; j++) { 10 | if (arr[i] + arr[j] == arr[0]) { 11 | if (output.length() > 0) { 12 | output.append(" "); 13 | } 14 | output.append(arr[i]).append(",").append(arr[j]); 15 | } 16 | } 17 | } 18 | return output.length() == 0 ? "-1" : output.toString(); 19 | } 20 | 21 | public static void main (String[] args) { 22 | // keep this function call here 23 | Scanner s = new Scanner(System.in); 24 | System.out.print(TwoSum(s.nextLine())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Easy/VowelCount.java: -------------------------------------------------------------------------------- 1 | import java.util.i*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int VowelCount(String str) { 7 | 8 | String vowels = "aeiou"; 9 | String[] strArray = str.split(""); 10 | 11 | int count = 0; 12 | for (int i = 0; i < strArray.length; i++) { 13 | if (vowels.contains(strArray[i])) { 14 | count++; 15 | } 16 | } 17 | return count; 18 | } 19 | 20 | public static void main (String[] args) { 21 | // keep this function call here 22 | Scanner s = new Scanner(System.in); 23 | System.out.print(VowelCount(s.nextLine())); 24 | } 25 | } -------------------------------------------------------------------------------- /Hard/AlphabetRunEncryption.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | static char SAG = 'R'; 7 | static char SOL = 'L'; 8 | static char IKIZ = 'S'; 9 | static char YOK = 'N'; 10 | static String HEPSI = "RLSN"; 11 | 12 | public static String StringChallenge(String str) { 13 | // code goes here 14 | 15 | StringBuilder result = new StringBuilder(""); 16 | char [] c = str.toCharArray(); 17 | 18 | for ( int i =c.length-1 ; i>=0 ; i--){ 19 | 20 | String parca = yeniParca(str,i); 21 | String sifre = kod(parca); 22 | 23 | if (i != c.length -1 && result.charAt(0) == sifre.charAt(sifre.length()-1)) { 24 | result = result.insert(0,sifre.substring(0,sifre.length()-1)); 25 | 26 | }else{ 27 | 28 | result = result.insert(0,sifre); 29 | 30 | } 31 | i-=parca.length()-1; 32 | 33 | } 34 | 35 | return result.toString(); 36 | } 37 | 38 | 39 | public static String yeniParca (String str,int s){ 40 | 41 | StringBuilder parca = new StringBuilder(""); 42 | boolean artan =str.charAt(s) < str.charAt(s-1); 43 | 44 | for ( int i = s ; i>=0; i--){ 45 | 46 | char c = str.charAt(i); 47 | 48 | if (HEPSI.indexOf(c) != -1 && parca.length()==0){ 49 | if (c==SAG || c==SOL || c== YOK){ 50 | return str.substring(s-1,s+1); 51 | }else if (c==IKIZ){ 52 | return str.substring(s-2,s+1); 53 | } 54 | } 55 | 56 | if (i==s){ 57 | parca = parca.append(c); 58 | continue; 59 | } 60 | 61 | char prevC = str.charAt(i+1); 62 | if (artan && c == (prevC +1) ){ 63 | parca = parca.insert(0,c); 64 | 65 | } else if (!artan && c== (prevC-1)) { 66 | parca = parca.insert(0,c); 67 | 68 | }else{ 69 | break; 70 | } 71 | } 72 | return parca.toString(); 73 | 74 | } 75 | 76 | public static String kod (String parca){ 77 | 78 | if (parca.indexOf(SAG) != -1){ 79 | char c = parca.charAt(0); 80 | return String.valueOf((char)(c-1))+String.valueOf((char)(c+1)); 81 | } else if (parca.indexOf(SOL) != -1){ 82 | char c = parca.charAt(0); 83 | return String.valueOf((char)(c+1)) + String.valueOf((char)(c-1)); 84 | } else if ( parca.indexOf(IKIZ) != -1){ 85 | return parca.substring(0,2); 86 | }else if (parca.indexOf(YOK) != -1){ 87 | char c = parca.charAt(0); 88 | return String.valueOf(c) + String.valueOf(c); 89 | 90 | } 91 | 92 | 93 | char bas = parca.charAt(0); 94 | char son = parca.charAt(parca.length()-1); 95 | 96 | if (bas>son){ 97 | return String.valueOf((char)(bas+1)) + String.valueOf((char)(son-1)); 98 | 99 | } 100 | 101 | return String.valueOf((char)(bas-1)) + String.valueOf((char)(son+1)); 102 | 103 | } 104 | 105 | public static void main (String[] args) { 106 | // keep this function call here 107 | Scanner s = new Scanner(System.in); 108 | System.out.print(StringChallenge(s.nextLine())); 109 | } 110 | 111 | } -------------------------------------------------------------------------------- /Hard/ArrayCouples.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.util.stream.Collectors; 3 | 4 | class Main { 5 | 6 | public static String ArrayCouples(int[] arr) { 7 | ArrayList pairs = new ArrayList(); 8 | ArrayList > allPairs = new ArrayList>(); 9 | int j = 0 ; 10 | for(int i = 0 ; i < arr.length-1 ; i += 2 ){ 11 | j = i + 1 ; 12 | pairs.add(arr[i]); 13 | pairs.add(arr[j]); 14 | allPairs.add(pairs); 15 | pairs = new ArrayList(); 16 | } 17 | ArrayList unPairs = findMatch( allPairs); 18 | if( unPairs.isEmpty()) {return "yes";} 19 | else { 20 | String listString = unPairs.stream().map(Object::toString) 21 | .collect(Collectors.joining(",")); 22 | return listString; 23 | } 24 | } 25 | public static ArrayList reversed(ArrayList list){ 26 | ArrayList rev = new ArrayList(); 27 | for (int i = list.size()-1 ; i >= 0 ; i--){ 28 | rev.add(list.get(i)); 29 | } 30 | return rev; 31 | } 32 | public static ArrayList findMatch ( ArrayList > allPairs ){ 33 | ArrayList unPairs = new ArrayList(); 34 | ArrayList reversed = new ArrayList(); 35 | ArrayList > checkPairs = new ArrayList>(); 36 | ArrayList > copyPairs = new ArrayList>(); 37 | for(int i = 0 ; i < allPairs.size() ; i++){ 38 | copyPairs.add(allPairs.get(i)); 39 | } 40 | for (ArrayList k : allPairs){ 41 | copyPairs.remove(k); 42 | reversed = reversed(k); 43 | if(!(copyPairs.contains(reversed))){ 44 | if(!(checkPairs.contains(reversed))){ 45 | unPairs.addAll(k); 46 | } 47 | } 48 | else{ 49 | checkPairs.add(k); 50 | } 51 | } 52 | return unPairs; 53 | } 54 | 55 | public static void main (String[] args) { 56 | // keep this function call here 57 | Scanner s = new Scanner(System.in); 58 | System.out.print(ArrayCouples(new int[] {5,4,6,7,7,6,4,5})); 59 | } 60 | } -------------------------------------------------------------------------------- /Hard/ArrayRotation.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static boolean StringChallenge(String str) { 7 | 8 | String[] arr= str.split(" "); 9 | 10 | for(int i=0; i card = new ArrayList(Arrays.asList(cardArr)); 14 | List cards = new ArrayList(Arrays.asList(strArr)); 15 | //System.out.println(hashMapCreater(card)); 16 | HashMap cardSet = hashMapCreater(card ); 17 | result(cards,cardSet); 18 | 19 | if(sum < 21 ) return "below " + out; //String.format() ? 20 | else if (sum > 21 ) return "above " + out; 21 | else return "blackjack " + out; 22 | } 23 | public static HashMap hashMapCreater(List card ){ 24 | HashMap cardSet = new HashMap(); 25 | int i = 1; 26 | for(String a : card ){ 27 | i++; 28 | if(card.indexOf(a) >= 10 ) i = 10; 29 | cardSet.put(a,i); 30 | } 31 | return cardSet; 32 | } 33 | public static void result(List strArr ,HashMap cardSet){ 34 | int max = 0 , temp = 0; 35 | for(String n : strArr ){ 36 | if(n.equals("ace")) count++; 37 | sum += cardSet.get(n); 38 | } 39 | List newArr = strArr; 40 | int j ; 41 | if(sum > 21 && count > 0){ 42 | sum -= 10 * count; 43 | for(j = 0 ; j < count ; j++){ 44 | newArr.remove("ace"); 45 | } 46 | } 47 | 48 | for(String b : newArr){ 49 | temp = cardSet.get(b); 50 | if(temp > max) { 51 | max = temp; 52 | out = b ; 53 | } 54 | } 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /Hard/Calculator.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | import java.util.regex.Matcher; 4 | import java.regex.Pattern; 5 | import java.util.Hashtable; 6 | import java.util.Dictionary; 7 | import java.util.Stack; 8 | import java.util.ArrayList; 9 | 10 | class Main { 11 | 12 | private static final Stack stack = new Stack<>(); 13 | private static String{} parseConsoleInput(String input) { 14 | return input 15 | .toLowerCase() 16 | .replaceAll("(\\)\\()",") * (") 17 | .replaceAll("([0-9])(?=[(])","$1 *") 18 | .replaceAll("([\\p{P}\\p{S}a-z0-9])(?=[\\p{P}\\p{S}a-z])", "$1 ") 19 | .replaceAll("([^0-9])(?=[0-9])", "$1 ") 20 | .replaceAll(" +", " ") 21 | .trim() 22 | .split(" "); 23 | } 24 | 25 | private static void printInputError(String op) { 26 | System.out.println("Unrecognised operator or operand: \"" + op + "\"."); 27 | } 28 | 29 | public static long reduceOperands(long a, long b, String operator) { 30 | switch (operator) { 31 | case "+": 32 | return a + b; 33 | case "-": 34 | return a - b; 35 | case "*": 36 | return a * b; 37 | case "/": 38 | if (b == 0) { 39 | System.out.println("Divide by 0."); 40 | throw new ArithmeticException(); 41 | } 42 | return a / b; 43 | default: 44 | return 0; 45 | } 46 | } 47 | 48 | private static boolean isOperand(String op) { 49 | Pattern pattern = Pattern.compile("^[\\d]|^-[\\d]"); 50 | Matcher matcher = pattern.matcher(op); 51 | return matcher.find(); 52 | } 53 | 54 | private static isOperator(String op) { 55 | Pattern pattern = Pattern.compile("^[+\\-*/^%]"); 56 | Matcher matcher = pattern.matcher(op); 57 | return matcher.find(); 58 | } 59 | 60 | private static String[] convertToPostfix(String[] tokens) { 61 | Stack infStack = new Stack<>(); 62 | String terminating = "#"; 63 | Dictionary precedence = new Hashtable<>() { 64 | { 65 | put(terminating, 0); 66 | put("(", 0); 67 | put(")", 0); 68 | put("+", 1); 69 | put("-", 1); 70 | put("*", 2); 71 | put("/", 2); 72 | } 73 | }; 74 | 75 | ArrayList output = new ArrayList<>(); 76 | infStack.push(terminating); 77 | for (String token : tokens) { 78 | if (isOperand(token)) { 79 | output.add(token); 80 | continue; 81 | } 82 | if (token.equals("(")) { 83 | infStack.push(token); 84 | continue; 85 | } 86 | if (token.equals(")")) { 87 | while(true) { 88 | String op = infStack.pop(); 89 | if(op.equals("(")) { 90 | break; 91 | } else { 92 | output.add(op); 93 | } 94 | } 95 | continue; 96 | } 97 | 98 | if (isOperator(token)) { 99 | int cmp1 = precedence.get(token); 100 | while(true) { 101 | int cmp2 = precedence.get(infStack.peek()); 102 | if (cmp1 > cmp2) { 103 | infStack.push(token); 104 | break; 105 | } else { 106 | output.add(infStack.pop()); 107 | } 108 | } 109 | } 110 | } 111 | 112 | while (!infStack.empty() && !infStack.peek().equals(terminating)) { 113 | output.add(infStack.pop()); 114 | } 115 | return output.toArray(new String[0]); 116 | } 117 | 118 | private static String performArithOperation(String operator) { 119 | if (stack.size() >= 2) { 120 | String elementB = stack.pop(); 121 | String elementA = stack.pop(); 122 | long opB = Long.parseLong(elementB); 123 | long opA = Long.parseLong(elementA); 124 | long result = reduceOperands(opA, opB, operator); 125 | return Long.toString(result); 126 | } else { 127 | return null; 128 | } 129 | } 130 | 131 | private static Long evaluateExpression(String[] tokens) { 132 | for (String token : tokens) { 133 | if (isOperand(token)) { 134 | stack.push(token); 135 | continue; 136 | } 137 | if (isOperator(token)) { 138 | String result = performArithOperation(token); 139 | if (result != null) { 140 | stack.push(result); 141 | } 142 | continue; 143 | } 144 | printInputError(token); 145 | } 146 | if (stack.isEmpty()) { 147 | return null; 148 | } 149 | return Long.parseLong(stack.peek()); 150 | } 151 | 152 | public static String Calculator(String[] args) { 153 | String[] tokens = parseConsoleInput(str); 154 | String[] postfix = convertToPostfix(tokens); 155 | Long result = evaluateExpression(postfix); 156 | return result == null ? "" : result.toString(); 157 | } 158 | 159 | public static void main(String[] args) { 160 | // keep this function call here 161 | Scanner s = new Scanner(System.in); 162 | System.out.print(Calculator(s.nextLine())); 163 | } 164 | } -------------------------------------------------------------------------------- /Hard/GasStation.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | private static final String IMPOSSIBLE = "impossible"; 7 | 8 | public static String GasStation(String[] strArr) { 9 | 10 | int circuitSize = strArr.length-1; 11 | int[] gas = new int[circuitSize]; 12 | int[] costs = new int[circuitSize]; 13 | 14 | for (int i = 1; i <= circuitSize; i++) { 15 | 16 | String[] gasAndCosts = strArr[i].split(":"); 17 | gas[i-1] = Integer.parseInt(gasAndCosts[0]); 18 | costs[i-1] = Integer.parseInt(gasAndCosts[1]); 19 | } 20 | 21 | for (int station = 0; station < circuitSize; station++) { 22 | 23 | String startIndex = getStartIndex(gas,costs,station); 24 | if (IMPOSSIBLE.equals(startIndex)) 25 | return startIndex; 26 | } 27 | return IMPOSSIBLE; 28 | } 29 | 30 | private static String getStartIndex(int[] gas, int[] costs, int[] startStation) { 31 | 32 | int circuitSize = gas.length; 33 | int nextStation = startStation < (circuitSize-1) ? startStation+1:0; 34 | int currentStation = startStation; 35 | int tank = 0; 36 | 37 | for (int i = 0; i < circuitSize; i++) { 38 | tank = tank - costs[currentStation]+gas[currentStation]; 39 | 40 | if (tank < 0) 41 | return IMPOSSIBLE; 42 | if (i == circuitSize-1) 43 | return String.valueOf(startStation+1); 44 | 45 | nextStation = nextStation < (circuitSize-1) ? nextStation+1:0; 46 | currentStation = currentStation < (circuitSize-1) ? currentStation+1:0; 47 | } 48 | return IMPOSSIBLE; 49 | } 50 | 51 | public static void main (String[] args) { 52 | //keep this function call here 53 | Scanner s = new Scanner(System.in); 54 | System.out.print(LongestWord(s.nextLine())); 55 | } 56 | } -------------------------------------------------------------------------------- /Hard/HamiltonianPath.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String HamiltonianPath(String[] strArr) { 7 | // code goes here 8 | String str= strArr[2].toString(); 9 | String strc= strArr[1].toString(); 10 | String hp=""; 11 | 12 | String strnew= str.replaceAll(",","").replace("(","").replace(")",""); 13 | for(int i=0;i knight_position = new ArrayList(2); 8 | for (int i = 0 ; i < str.length() ; i++) { 9 | if( Character.isDigit(str.charAt(i))) { 10 | knight_position.add(Integer.parseInt(String.valueOf(str.charAt(i)))); 11 | } 12 | } 13 | int count = 0; 14 | int x,y ; 15 | 16 | for(int i = 0 ; i < moves.length ; i++){ 17 | x = knight_position.get(0) + moves[i][0]; 18 | y = knight_position.get(1) + moves[i][1]; 19 | 20 | if ( 0< x && x <= 8 && 0 < y && y <= 8) { 21 | count++; 22 | } 23 | } 24 | return count; 25 | } 26 | 27 | public static void main (String[] args) { 28 | // keep this function call here 29 | Scanner s = new Scanner(System.in); 30 | System.out.print(KnightJumps(s.nextLine())); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /Hard/LineOdering.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | static List> permutations = new ArrayList<>(); 5 | 6 | public static int LineOrdering(String[] strArr) { 7 | // code goes here 8 | if(strArr.length>10){ 9 | return 0; 10 | } 11 | permute(findChar(strArr),0); 12 | int possibility = 0; 13 | for(List l : permutations){ 14 | if(relations(l,strArr)) possibility++; 15 | } 16 | 17 | return possibility; 18 | } 19 | static boolean relations(Listpossible,String arr[]){ 20 | for(String item : arr){ 21 | String posarr[] = new String[2]; 22 | if(item.contains("<")){ 23 | posarr = item.split("<"); 24 | String temp = posarr[0]; 25 | posarr[0] = posarr[1]; 26 | posarr[1] = temp; 27 | 28 | }else{ 29 | posarr = item.split(">"); 30 | } 31 | if(possible.indexOf(posarr[0]) <= possible.indexOf(posarr[1])){ 32 | return false; 33 | } 34 | } 35 | return true; 36 | } 37 | static List findChar(String strArr[]){ 38 | Set chr = new HashSet<>(); 39 | for(String str : strArr){ 40 | if(str.contains("<")){ 41 | chr.addAll(Arrays.asList(str.split("<"))); 42 | }else if(str.contains(">")){ 43 | chr.addAll(Arrays.asList(str.split(">"))); 44 | } 45 | } 46 | return new ArrayList<>(chr); 47 | } 48 | 49 | static void permute(List arr, int k){ 50 | for(int i = k; i < arr.size(); i++){ 51 | java.util.Collections.swap(arr, i, k); 52 | permute(arr, k+1); 53 | java.util.Collections.swap(arr, k, i); 54 | } 55 | if (k == arr.size() -1){ 56 | permutations.add(new ArrayList<>(arr)); 57 | } 58 | } 59 | 60 | public static void main(String args[]){ 61 | System.out.println(LineOrdering(new String[]{"A>B","B>C","AB","B 0) { 44 | rowHistogram[k] += numArr[i][k]; 45 | } else { 46 | rowHistogram[k] = 0; 47 | } 48 | 49 | if (numArr[k][i] > 0) { 50 | colHistogram[k] += numArr[k][i]; 51 | } else { 52 | colHistogram[k] = 0; 53 | } 54 | } 55 | } 56 | 57 | if (getMax(rowHistogram) > getMax(colHistogram)) { 58 | maxArea = getMax(rowHistogram); 59 | } else { 60 | maxArea = getMax(colHistogram); 61 | } 62 | 63 | return maxArea; 64 | } 65 | 66 | public static void main (String[] args) { 67 | // keep this function call here 68 | Scanner s = new Scanner(System.in); 69 | System.out.print(MaximalRectangle(s.nextLine())); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /Hard/MaximalSquare.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int MaximalSquare(String[] strArr) { 7 | 8 | char [][] arr1 = new char[strArr.length][strArr[0].length()]; 9 | 10 | for (int i =0 ; imax){ 33 | 34 | max=arr2[i][j]; 35 | } 36 | } 37 | } 38 | } 39 | 40 | return max*max; 41 | } 42 | 43 | public static void main (String[] args) { 44 | // keep this function call here 45 | Scanner s = new Scanner(System.in); 46 | System.out.print(MaximalSquare(s.nextLine())); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Hard/NimWinner.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int NimWinner(int[] arr) { 7 | 8 | int mResult = 0, x = 0; 9 | 10 | for (int i = 0; i < arr.length; i++) { 11 | x ^= arr[i]; 12 | mResult = x > 0 ? 1 : 2; 13 | } 14 | return mResult; 15 | } 16 | 17 | public static void main(String[] args) { 18 | // keep this function call here 19 | Scanner s = new Scanner(System.in); 20 | System.out.print(NimWinner(s.nextLine())); 21 | } 22 | } -------------------------------------------------------------------------------- /Hard/NumberEncoding.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String StringChallenge(String str) { 7 | // code goes here 8 | String result=""; 9 | str.toLowerCase(); 10 | for(int i=0;i permutations = new ArrayList<>(); 7 | public static Integer[] minPermutationsArr = new Integer[0]; 8 | public static Integer minCost = Integer.MAX_VALUE; 9 | 10 | public static String OptimalAssignments(String[] strArr) { 11 | // code goes here 12 | Integer[][] matrix = new Integer[strArr.length][strArr.length]; 13 | 14 | minPermutationsArr = new Integer[matrix.lenght]; 15 | 16 | for (int i = 0; i < strArr.length; i++) { 17 | String[] splitted = strArr[i].subString(1,strArr[i].length()-1).split(","); 18 | 19 | for (int j = 0; j < splitted.length; j++) { 20 | matrix[i][j] = Integer.parseInt(splitted[j]); 21 | } 22 | } 23 | 24 | List list = new ArrayList<>(); 25 | 26 | for (int i = 0; i < matrix.length; i++) { 27 | list.add(i); 28 | } 29 | 30 | permute(list,0); 31 | 32 | for (Integer[] permutation : permutations) { 33 | int cost = 0; 34 | 35 | for (int i = 0; i < permutation.length; i++) { 36 | cost += matrix[i]permutation[i]; 37 | } 38 | 39 | if (cost < minCost) { 40 | minCost = cost; 41 | minPermutationsArr = permutation; 42 | } 43 | } 44 | 45 | String result = ""; 46 | 47 | for (int i = 0; i < minPermutationsArr.length; i++) { 48 | result += "(" + (i + 1) + "-" + (minPermutationsArr[i]+1)+")"; 49 | } 50 | return result; 51 | } 52 | 53 | static void permute(List list, int k) { 54 | for (int i = k; i < list.size(); i++) { 55 | Collections.swap(list,i,k); 56 | permute(list,k + 1); 57 | Collections.swap(list,k,i); 58 | } 59 | 60 | if (k == list.size() -1) { 61 | Integer[] arr = list.toArray(new Integer[list.size()]); 62 | permutations.add(arr); 63 | } 64 | } 65 | 66 | public static void main (String[] args) { 67 | // keep this function call here 68 | Scanner s = new Scanner(System.in); 69 | System.out.print(OptimalAssignments(s.nextLine())); 70 | } 71 | } -------------------------------------------------------------------------------- /Hard/ParallelSums.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | 5 | public static String ParallelSums(int[] arr) { 6 | int[] firstSet = new int[arr.length / 2]; 7 | int[] secondSet = new int[arr.length / 2]; 8 | 9 | Arrays.sort(arr); 10 | 11 | int indexOfSet1 = 0; 12 | int indexOfSet2 = 0; 13 | int sumOfSet1 = 0; 14 | int sumOfSet2 = 0; 15 | int lastIndexOfArr = arr.length -1; 16 | 17 | while (indexOfSet1 < firstSet.length && indexOfSet2 < firstSet.length) { 18 | if (sumOfSet1 < sumOfSet2) { 19 | firstSet[indexOfSet1] = arr[lastIndexOfArr]; 20 | indexOfSet1++; 21 | sumOfSet1 += arr[lastIndexOfArr]; 22 | } else { 23 | secondSet[indexOfSet2] = arr[lastIndexOfArr]; 24 | indexOfSet2++; 25 | sumOfSet2 += arr[lastIndexOfArr]; 26 | } 27 | lastIndexOfArr--; 28 | } 29 | 30 | while (lastIndexOfArr >= 0) { 31 | if (indexOfSet1 < firstSet.length) { 32 | firstSet[indexOfSet1++] = arr[lastIndexOfArr]; 33 | sumOfSet1 += arr[lastIndexOfArr]; 34 | } else { 35 | secondSet[indexOfSet2++] = arr[lastIndexOfArr]; 36 | sumOfSet2 += arr[lastIndexOfArr]; 37 | } 38 | lastIndexOfArr--; 39 | } 40 | if (sumOfSet1 != sumOfSet2) { 41 | return String.valueOf(-1); 42 | } 43 | 44 | Arrays.sort(firstSet); 45 | Arrays.sort(secondSet); 46 | 47 | StringBuilder sb = new StringBuilder(); 48 | if (firstSet[0] < secondSet[0]) { 49 | for (int intSet1 : firstSet) { 50 | sb.append(intSet1).append(","); 51 | } 52 | for (int intSet2 : secondSet) { 53 | sb.append(intSet2).append(","); 54 | } 55 | } 56 | sb.setLength(sb.length()-1); 57 | return sb.toString(); 58 | } 59 | 60 | public static void main (String[] args) { 61 | //keep this function call here 62 | Scanner s = new Scanner(System.in); 63 | System.out.print(ParallelSums(s.nextLine())); 64 | } 65 | } -------------------------------------------------------------------------------- /Hard/PascalTriangle.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int PascalsTriangle(int[] arr) { 7 | 8 | if (arr[arr.length - 1] == 1) { 9 | return -1; 10 | } else { 11 | int result = 0; 12 | int n = arr[1] + 1; 13 | int[][] arr2 = new int[n][n]; 14 | 15 | for (int line = 0; line < n; line++) { 16 | for (int i = 0; i <= line; i++) { 17 | if (line == i || i == 0) 18 | arr2[line][i] = 1; 19 | else 20 | arr2[line][i] = arr2[line - 1][i - 1] + arr2[line - 1][i]; 21 | } 22 | if ((n - line) == 1) { 23 | result = arr2[line][arr.length]; 24 | } 25 | } 26 | return result; 27 | } 28 | } 29 | 30 | public static void main(String[] args) { 31 | // keep this function call here 32 | //Scanner s = new Scanner(System.in); 33 | //System.out.print(PascalsTriangle(s.nextLine())); 34 | System.out.println(PascalsTriangle(new int[]{1, 3})); // 3 35 | System.out.println(PascalsTriangle(new int[]{1, 5, 10, 10})); // 5 36 | System.out.println(PascalsTriangle(new int[]{1, 5, 10, 10, 5, 1})); 37 | System.out.println(PascalsTriangle(new int[]{1, 5, 10, 10, 5})); 38 | } 39 | } -------------------------------------------------------------------------------- /Hard/RomanNumeralReduction.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String StringChallenge(String str) { 7 | char []arr = str.toCharArray(); 8 | int []nums= {1,5,10,50,100,500,1000}; 9 | char []rom={'I','V','X','L','C','D','M'}; 10 | int num=0; 11 | int count=0; 12 | String ret = ""; 13 | String exit = ""; 14 | 15 | for(int i=0;i=0;z--){ 23 | count = num / Integer.valueOf(nums[z]); 24 | num=num%Integer.valueOf(nums[z]); 25 | if(count >0){ 26 | ret = Print(count, String.valueOf(rom[z])); 27 | exit = exit+ret; 28 | } 29 | }return exit; 30 | } 31 | public static String Print(int sub, String word){ 32 | String back = ""; 33 | for(int i =0; i1) return "false"; 16 | if(Character.isAlphabetic(letter)) return "false"; 17 | } 18 | 19 | if (comma!=0){ 20 | 21 | String [] number = strArr[0].split(","); 22 | // 1,453,44,443.03 23 | for ( int i = 1 ; i3) return "false"; 32 | 33 | }else{ // 10.00 34 | 35 | if(point != 0){ 36 | String last = strArr[0].substring(0,strArr[0].indexOf('.')); 37 | if ( last.length() > 3 ) return "false"; 38 | }else{ 39 | // 1243 40 | if (strArr[0].length() > 3) return "false"; 41 | } 42 | 43 | 44 | } 45 | 46 | 47 | return "true"; 48 | } 49 | 50 | public static void main (String[] args) { 51 | // keep this function call here 52 | Scanner s = new Scanner(System.in); 53 | System.out.print(StringChallenge(s.nextLine())); 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /Hard/StepWalking.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | 5 | public static int count = 0; 6 | 7 | public static void wayToStep(int num,List path) { 8 | if (num == 0) { 9 | for (Integer i: path) { 10 | 11 | } 12 | count += 1; 13 | } else if (num == 1) { 14 | List newPath = new ArrayList(path); 15 | newPath.add(1); 16 | wayToStep(num-1, newPath); 17 | } else if (num > 1) { 18 | List newPath1 = new ArrayList(path); 19 | newPath1.add(1); 20 | wayToStep(num-1, newPath1); 21 | 22 | List newPath2 = new ArrayList(path); 23 | newPath2.add(2); 24 | wayToStep(num-2, newPath2); 25 | } 26 | } 27 | 28 | public static int StepWalking(int num) { 29 | List combiList = new ArrayList(); 30 | wayToStep(num, combiList); 31 | return count; 32 | } 33 | 34 | public static void main (String[] args) { 35 | //keep this function call here 36 | Scanner s = new Scanner(System.in); 37 | System.out.print(StepWalking(s.nextLine())); 38 | } 39 | } -------------------------------------------------------------------------------- /Hard/SudokuQuadrantChecker.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.util.stream.Collectors; 3 | 4 | class Main { 5 | public static ArrayList quadLocation = new ArrayList<>(); 6 | public static HashSet invalids = new HashSet<>(); 7 | 8 | public static String sudokuQuadrantChecker(String[] arr) { 9 | ArrayList>board = buildBoard(arr); 10 | fillQuadHash(); 11 | 12 | for (int i = 0 ; i < board.get(0).size() ; i++) { 13 | 14 | checkRow(board.get(i),i); 15 | } 16 | for (int i = 0 ; i < board.get(0).size() ; i++) { 17 | checkColumn(buildColumn(board, i),i); 18 | } 19 | 20 | for (int i = 0 ; i < board.get(0).size() ; i++) { 21 | checkQuadrant(buildQuad(board,i),i); 22 | } 23 | if (invalids.isEmpty()) { 24 | return "legal"; 25 | } 26 | List strArr = invalids.stream().collect(Collectors.toList()); 27 | Collections.sort(strArr); 28 | return strArr.stream().map(String::valueOf).collect(Collectors.joining(",")); 29 | } 30 | public static ArrayList> buildBoard(String[] arr) { 31 | ArrayList> board = new ArrayList<>(); 32 | for (String n : arr) { 33 | char[] nChar = n.toCharArray(); 34 | ArrayList row = new ArrayList<>(); 35 | for (char c : nChar) { 36 | if (Character.isDigit(c)) { 37 | row.add(Character.toString(c)); 38 | } 39 | else if (c == 'x') { 40 | row.add("x"); 41 | } 42 | } 43 | board.add(row); 44 | } 45 | return board; 46 | } 47 | public static void fillQuadHash() { 48 | quadLocation.add(new Integer[]{3,3}); 49 | quadLocation.add(new Integer[]{3,6}); 50 | quadLocation.add(new Integer[]{3,9}); 51 | quadLocation.add(new Integer[]{6,3}); 52 | quadLocation.add(new Integer[]{6,6}); 53 | quadLocation.add(new Integer[]{6,9}); 54 | quadLocation.add(new Integer[]{9,3}); 55 | quadLocation.add(new Integer[]{9,6}); 56 | quadLocation.add(new Integer[]{9,9}); 57 | } 58 | public static ArrayList buildQuad(ArrayList> board,int quadNum){ 59 | int x = quadLocation.get(quadNum)[0]; 60 | int y = quadLocation.get(quadNum)[1]; 61 | ArrayList quad = new ArrayList<>(); 62 | for (int i = x - 3 ; i < x ; i++) { 63 | for (int j = y -3 ; j < y ; j++) { 64 | quad.add(board.get(i).get(j)); 65 | } 66 | } 67 | return quad; 68 | } 69 | public static ArrayList buildColumn(ArrayList> board, int i) { 70 | ArrayListcolumn= new ArrayList<>(); 71 | for (ArrayList row : board) { 72 | column.add(row.get(i)); 73 | } 74 | return column; 75 | } 76 | public static int isValid(int x , int y ) { 77 | int a, b ,loc = 0; 78 | for (int i = 0 ; i < quadLocation.size() ; i++) { 79 | a = quadLocation.get(i)[0]; 80 | b = quadLocation.get(i)[1]; 81 | if ( a-3 <= x && x < a && b-3 <= y && y < b) { 82 | loc = ++i; //compiler ++ order !!! 83 | } 84 | } 85 | return loc; 86 | } 87 | public static void checkRow(ArrayList row,int k){ 88 | 89 | String a , b ; 90 | for(int i = 0 ; i < row.size() ; i++){ 91 | for(int j = 0 ; j < row.size() ; j++){ 92 | a = row.get(i); 93 | b = row.get(j); 94 | if(a.equals(b) && !a.equals("x") && i != j){ 95 | //System.out.println(k + " " + j); 96 | invalids.add(isValid(k,j)); 97 | } 98 | } 99 | } 100 | } 101 | public static void checkColumn(ArrayList row,int k){ 102 | String a , b ; 103 | for(int i = 0 ; i < row.size() ; i++){ 104 | for(int j = 0 ; j < row.size() ; j++){ 105 | a = row.get(i); 106 | b = row.get(j); 107 | if(a.equals(b) && !a.equals("x") && i != j){ 108 | invalids.add(isValid(j,k)); 109 | } 110 | } 111 | } 112 | } 113 | public static void checkQuadrant(ArrayList row,int k){ 114 | String a , b ; 115 | for(int i = 0 ; i < row.size() ; i++){ 116 | for(int j = 0 ; j < row.size() ; j++){ 117 | a = row.get(i); 118 | b = row.get(j); 119 | if(a.equals(b) && !a.equals("x") && i != j){ 120 | //System.out.println(k + " " + j); 121 | invalids.add(k+1); 122 | } 123 | } 124 | } 125 | } 126 | public static void main(String[] args) { 127 | String[] arr = { 128 | "(1,2,3,4,5,6,7,8,9)", 129 | "(x,x,x,x,x,x,x,x,x)", 130 | "(6,x,5,x,3,x,x,4,x)", 131 | "(2,x,1,1,x,x,x,x,x)", 132 | "(x,x,x,x,x,x,x,x,x)", 133 | "(x,x,x,x,x,x,x,x,x)", 134 | "(x,x,x,x,x,x,x,x,x)", 135 | "(x,x,x,x,x,x,x,x,x)", 136 | "(x,x,x,x,x,x,x,x,9)"}; 137 | String[] arr2 = { 138 | "(1,1,3,4,5,6,7,8,1)", 139 | "(x,x,x,x,x,x,x,x,x)", 140 | "(x,x,x,x,x,x,x,x,x)", 141 | "(1,x,x,x,x,x,x,x,x)", 142 | "(x,x,x,x,x,x,x,x,x)", 143 | "(x,x,x,x,x,x,x,x,x)", 144 | "(x,x,x,x,x,x,x,x,x)", 145 | "(x,x,x,x,x,x,x,x,x)", 146 | "(x,x,x,x,x,x,x,x,x)"}; 147 | String[] arr3 = {"(1,2,3,4,5,6,7,8,9)","(x,x,x,x,x,x,x,x,x)","(6,x,5,x,3,x,x,4,x)","(2,x,1,1,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)"}; 148 | String[] arr4 = {"(1,2,3,4,5,6,7,8,9)","(x,x,x,x,x,x,x,x,x)","(6,x,5,x,3,x,x,4,x)","(2,x,1,5,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,8)"}; 149 | String[] arr5 = {"(1,2,3,4,5,6,7,8,9)","(x,x,x,x,x,x,x,x,x)","(6,x,5,x,3,x,x,4,x)","(2,x,1,5,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,4)","(9,1,2,3,4,5,6,7,8)"}; 150 | String[] arr6 = {"(1,2,3,4,5,6,7,8,9)","(4,5,6,1,2,3,x,x,x)","(7,8,9,x,x,6,x,x,x)","(2,3,4,x,x,x,x,x,x)","(5,6,7,x,x,x,x,x,x)","(8,9,1,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,1)"}; 151 | String[] arr7 = {"(1,2,3,4,5,6,7,8,9)","(x,x,x,x,x,x,x,x,x)","(6,x,5,x,3,x,x,4,x)","(2,x,1,5,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,x)","(x,x,x,x,x,x,x,x,9)","(9,1,2,3,4,5,6,7,8)"}; 152 | System.out.println(sudokuQuadrantChecker(arr4)); 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /Hard/SwitchSort.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import javafx.scene.paint.CycleMethod; 3 | import java.io.*; 4 | 5 | class Main { 6 | 7 | public static int SwitchSort(int[] arr) { 8 | //code goes here 9 | int len = arr.length; 10 | HashMap map = new HashMap<>(); 11 | for (int i = 0; i < len; i++) { 12 | map.put(arr[i], i); 13 | } 14 | Arrays.sort(arr); 15 | boolean[] isChanged = new boolean[len]; 16 | Arrays.fill(isChanged, false); 17 | 18 | int SwitchCount = 0; 19 | for (int i = 0; i < len; i++) { 20 | if (isChanged[i] || map.get(arr[i]) == i) 21 | continue; 22 | 23 | int j = i, cycle = 0; 24 | while (!isChanged[j]) { 25 | isChanged[j] = true; 26 | j = map.get(arr[j]); 27 | cycle++; 28 | } 29 | if (cycle > 0) { 30 | SwitchCount += (cycle-1); 31 | } 32 | } 33 | return SwitchCount; 34 | } 35 | 36 | public static void main (String[] args) { 37 | //keep this function call here 38 | Scanner s = new Scanner(System.in); 39 | System.out.print(SwitchSort(s.nextLine())); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Hard/TetrisMove.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String StringChallenge(String str) { 7 | int num = 0; 8 | String stringFinal = ""; 9 | for(int i = 0; i=1000){ 20 | stringFinal+="M"; 21 | num-=1000; 22 | } 23 | while(num>=500){ 24 | stringFinal+="D"; 25 | num-=500; 26 | } 27 | while(num>=100){ 28 | stringFinal+="C"; 29 | num-=100; 30 | } 31 | while(num>=50){ 32 | stringFinal+="L"; 33 | num-=50; 34 | } 35 | while(num>=10){ 36 | stringFinal+="X"; 37 | num-=10; 38 | } 39 | while(num>=5){ 40 | stringFinal+="V"; 41 | num-=5; 42 | } 43 | while(num>=1){ 44 | stringFinal+="I"; 45 | num-=1; 46 | if(num-1<0)num=0; 47 | } 48 | } 49 | str = stringFinal; 50 | return str; 51 | } 52 | 53 | public static void main (String[] args) { 54 | // keep this function call here 55 | Scanner s = new Scanner(System.in); 56 | System.out.print(StringChallenge(s.nextLine())); 57 | } 58 | 59 | } 60 | Fevzi Yüksel — 17.11.2022 20:06 61 | public class RomanNumeralReduction 62 | { 63 | public static String reduction(String str) 64 | { 65 | Map numeralMap = Map.of( 66 | 'I', 1, 67 | 'V', 5, 68 | 'X', 10, 69 | 'L', 50, 70 | 'C', 100, 71 | 'D', 500, 72 | 'M', 1000); 73 | 74 | TreeMap orderedMap = new TreeMap<>(Comparator.reverseOrder()); 75 | for(var pair : numeralMap.entrySet()) 76 | orderedMap.put(pair.getValue(), pair.getKey()); 77 | 78 | int sum = 0; 79 | for(char c : str.toCharArray()) 80 | sum += numeralMap.get(c); 81 | 82 | StringBuilder builder = new StringBuilder(str.length()); 83 | for(var key : orderedMap.keySet()) 84 | { 85 | while(sum >= key) 86 | { 87 | sum -= key; 88 | builder.append(orderedMap.get(key)); 89 | } 90 | } 91 | 92 | return builder.toString(); 93 | } 94 | public static void main(String[] args) 95 | { 96 | List cases = List.of("LLLXXXVVVV", "XXXVVIIIIIIIIII", "DDLL", "MM", "CCCCLL", "CCCCCCCCLLLL", "IIIII", 97 | "IIIIIIIIII", "XXXVVVIIIII", "LXXXVVVIIIII"); 98 | 99 | List results = List.of("CC", "L", "MC", "MM", "D", "M", "V", "X", "L", "C"); 100 | 101 | cases.stream().map(RomanNumeralReduction::reduction2).forEach(System.out::println); 102 | 103 | System.out.println(Objects.equals(cases.stream().map(RomanNumeralReduction::reduction2).toList(), results)); 104 | 105 | 106 | } 107 | } 108 | public static String reduction2(String str) 109 | { 110 | Map numeralMap = Map.of( 111 | 'I', 1, 112 | 'V', 5, 113 | 'X', 10, 114 | 'L', 50, 115 | 'C', 100, 116 | 'D', 500, 117 | 'M', 1000); 118 | 119 | TreeMap orderedMap = new TreeMap<>(Comparator.reverseOrder()); 120 | for(var pair : numeralMap.entrySet()) 121 | orderedMap.put(pair.getValue(), pair.getKey()); 122 | 123 | int sum = 0; 124 | for(char c : str.toCharArray()) 125 | sum += numeralMap.get(c); 126 | 127 | StringBuilder builder = new StringBuilder(str.length()); 128 | for(var pair : orderedMap.entrySet()) 129 | { 130 | int value = pair.getKey(), noLetter = sum / value; 131 | 132 | while(0 < noLetter-- ) 133 | builder.append(pair.getValue()); 134 | 135 | sum %= value; 136 | } 137 | 138 | return builder.toString(); 139 | } 140 | dilara — 17.11.2022 20:07 141 | import java.util.*; 142 | import java.io.*; 143 | 144 | class Main { 145 | 146 | public static String RomanNumearalReduction(String str) { 147 | // code goes here 148 | LinkedHashMap hsh = new LinkedHashMap(); 149 | hsh.put('M',1000); 150 | hsh.put('D',500); 151 | hsh.put('C',100); 152 | hsh.put('L',50); 153 | hsh.put('X',10); 154 | hsh.put('V',5); 155 | hsh.put('I',1); 156 | int result=0; 157 | int result1=0; 158 | String strResult=""; 159 | Character s =' '; 160 | for(int i=0;i map: hsh.entrySet() ){ 165 | char value = map.getKey(); 166 | int key = map.getValue(); 167 | result1= result/key; 168 | result= result%key; 169 | for(int j=0;j= 0){ 224 | newstr += "M"; 225 | num -=1000; 226 | }else if (num-500 >= 0){ 227 | newstr += "D"; 228 | num -=500; 229 | }else if (num-100 >= 0){ 230 | newstr += "C"; 231 | num -=100; 232 | }else if (num-50 >= 0){ 233 | newstr += "L"; 234 | num -=50; 235 | }else if (num-10 >= 0){ 236 | newstr += "X"; 237 | num -=10; 238 | }else if (num-5 >= 0){ 239 | newstr += "V"; 240 | num -=5; 241 | }else if (num-1 >= 0){ 242 | newstr += "I"; 243 | num -=1; 244 | } 245 | 246 | return num ==0 ? newstr : repeat(num); 247 | } 248 | ` 249 | Kamil H. — 17.11.2022 21:14 250 | //işlem M 251 | if (total/1000!=0 && total%1000!=0){ 252 | for (int j=0;j max) { 310 | max = count; 311 | } 312 | } 313 | } 314 | } 315 | return max; 316 | } 317 | ... 318 | import java.util.*; import java.io.*; 319 | 320 | class Main { 321 | public static int I(int[][] arr){ 322 | int count=0; 323 | int max=0; 324 | Genişlet 325 | message.txt 326 | 14 KB 327 | public static int L(int[][] arr){ 328 | int count=0; 329 | int max=0; 330 | for(int k=0;k<7;k++){ 331 | for(int m=0;m<11;m++){ 332 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+2][m]==1){ 333 | 334 | if(reduction(k,2,arr)==1){ 335 | count++; 336 | } 337 | if(reduction(k+1,1,arr)==1){ 338 | count++; 339 | } 340 | if(reduction(k+2,1,arr)==1){ 341 | count++; 342 | } 343 | if(count>max){ 344 | max=count; 345 | } 346 | } 347 | 348 | } 349 | } 350 | for(int k=0;k<7;k++){ 351 | for(int m=0;m<11;m++){ 352 | count=0; 353 | if(arr[k][m+1]==1&&arr[k+1][m+1]==1&&arr[k+2][m]==1&&arr[k+2][m+1]==1){ 354 | 355 | if(reduction(k,1,arr)==1){ 356 | count++; 357 | } 358 | if(reduction(k+1,1,arr)==1){ 359 | count++; 360 | } 361 | if(reduction(k+2,2,arr)==1){ 362 | count++; 363 | } 364 | if(count>max){ 365 | max=count; 366 | } 367 | } 368 | } 369 | } 370 | for(int k=0;k<8;k++){ 371 | for(int m=0;m<10;m++){ 372 | count=0; 373 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k][m+2]==1&&arr[k+1][m+2]==1){ 374 | 375 | if(reduction(k,3,arr)==1){ 376 | count++; 377 | } 378 | if(reduction(k+1,1,arr)==1){ 379 | count++; 380 | } 381 | if(count>max){ 382 | max=count; 383 | } 384 | } 385 | } 386 | } 387 | ... 388 | public static int L(int[][] arr){ 389 | int count=0; 390 | int max=0; 391 | for(int k=0;k<7;k++){ 392 | for(int m=0;m<11;m++){ 393 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+2][m]==1){ 394 | Genişlet 395 | message.txt 396 | 12 KB 397 | for(int k=0;k<8;k++){ 398 | for(int m=0;m<10;m++){ 399 | count=0; 400 | if(arr[k][m]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+1][m+2]==1){ 401 | 402 | if(reduction(k,1,arr)==1){ 403 | count++; 404 | } 405 | if(reduction(k+1,3,arr)==1){ 406 | count++; 407 | } 408 | if(count>max){ 409 | max=count; 410 | } 411 | } 412 | } 413 | } 414 | return max; 415 | } 416 | public static int J(int[][] arr){ 417 | int count=0; 418 | int max=0; 419 | 420 | for(int k=0;k<7;k++){ 421 | for(int m=0;m<11;m++){ 422 | if(arr[k][m]==1&&arr[k+1][m]==1&&arr[k+2][m]==1&&arr[k+2][m+1]==1){ 423 | 424 | if(reduction(k,1,arr)==1){ 425 | count++; 426 | } 427 | if(reduction(k+1,1,arr)==1){ 428 | count++; 429 | } 430 | if(reduction(k+2,2,arr)==1){ 431 | count++; 432 | } 433 | if(count>max){ 434 | max=count; 435 | } 436 | } 437 | 438 | } 439 | } 440 | for(int k=0;k<7;k++){ 441 | for(int m=0;m<11;m++){ 442 | count=0; 443 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k+1][m+1]==1&&arr[k+2][m+1]==1){ 444 | 445 | if(reduction(k,2,arr)==1){ 446 | count++; 447 | } 448 | if(reduction(k+1,1,arr)==1){ 449 | count++; 450 | } 451 | if(reduction(k+2,1,arr)==1){ 452 | count++; 453 | } 454 | if(count>max){ 455 | max=count; 456 | } 457 | } 458 | } 459 | } 460 | ... 461 | for(int k=0;k<8;k++){ 462 | for(int m=0;m<10;m++){ 463 | count=0; 464 | if(arr[k][m]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+1][m+2]==1){ 465 | 466 | if(reduction(k,1,arr)==1){ 467 | Genişlet 468 | message.txt 469 | 10 KB 470 | for(int k=0;k<8;k++){ 471 | for(int m=0;m<10;m++){ 472 | count=0; 473 | if(arr[k][m+2]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+1][m+2]==1){ 474 | 475 | if(reduction(k,1,arr)==1){ 476 | count++; 477 | } 478 | if(reduction(k+1,3,arr)==1){ 479 | count++; 480 | } 481 | if(count>max){ 482 | max=count; 483 | } 484 | } 485 | } 486 | } 487 | for(int k=0;k<8;k++){ 488 | for(int m=0;m<10;m++){ 489 | count=0; 490 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k][m+2]==1&&arr[k+1][m]==1){ 491 | 492 | if(reduction(k,3,arr)==1){ 493 | count++; 494 | } 495 | if(reduction(k+1,1,arr)==1){ 496 | count++; 497 | } 498 | if(count>max){ 499 | max=count; 500 | } 501 | } 502 | } 503 | } 504 | 505 | return max; 506 | } 507 | ... 508 | for(int k=0;k<8;k++){ 509 | for(int m=0;m<10;m++){ 510 | count=0; 511 | if(arr[k][m+2]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+1][m+2]==1){ 512 | 513 | if(reduction(k,1,arr)==1){ 514 | Genişlet 515 | message.txt 516 | 8 KB 517 | public static int O(int[][] arr){ 518 | int count=0; 519 | int max=0; 520 | 521 | for(int k=0;k<8;k++){ 522 | for(int m=0;m<11;m++){ 523 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1){ 524 | 525 | if(reduction(k,2,arr)==1){ 526 | count++; 527 | } 528 | if(reduction(k+1,2,arr)==1){ 529 | count++; 530 | } 531 | if(count>max){ 532 | max=count; 533 | } 534 | } 535 | 536 | } 537 | } 538 | return max; 539 | 540 | } 541 | public static int S(int[][] arr){ 542 | int count=0; 543 | int max=0; 544 | 545 | for(int k=0;k<8;k++){ 546 | for(int m=0;m<10;m++){ 547 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k+1][m+1]==1&&arr[k+1][m+2]==1){ 548 | 549 | if(reduction(k,2,arr)==1){ 550 | count++; 551 | } 552 | if(reduction(k+1,2,arr)==1){ 553 | count++; 554 | } 555 | if(count>max){ 556 | max=count; 557 | } 558 | } 559 | 560 | } 561 | } 562 | ... 563 | } 564 | public static int O(int[][] arr){ 565 | int count=0; 566 | int max=0; 567 | 568 | for(int k=0;k<8;k++){ 569 | for(int m=0;m<11;m++){ 570 | Genişlet 571 | message.txt 572 | 7 KB 573 | for(int k=0;k<7;k++){ 574 | for(int m=0;m<11;m++){ 575 | count=0; 576 | if(arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+2][m]==1){ 577 | 578 | if(reduction(k,1,arr)==1){ 579 | count++; 580 | } 581 | if(reduction(k+1,2,arr)==1){ 582 | count++; 583 | } 584 | if(reduction(k+2,1,arr)==1){ 585 | count++; 586 | } 587 | if(count>max){ 588 | max=count; 589 | } 590 | } 591 | } 592 | } 593 | return max; 594 | } 595 | ... 596 | for(int k=0;k<7;k++){ 597 | for(int m=0;m<11;m++){ 598 | count=0; 599 | if(arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+2][m]==1){ 600 | 601 | if(reduction(k,1,arr)==1){ 602 | Genişlet 603 | message.txt 604 | 6 KB 605 | for(int k=0;k<7;k++){ 606 | for(int m=0;m<11;m++){ 607 | count=0; 608 | if(arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+2][m]==1){ 609 | 610 | if(reduction(k,1,arr)==1){ 611 | Genişlet 612 | message.txt 613 | 6 KB 614 | public static int T(int[][] arr){ 615 | int count=0; 616 | int max=0; 617 | 618 | for(int k=0;k<7;k++){ 619 | for(int m=0;m<11;m++){ 620 | if(arr[k][m]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+2][m]==1){ 621 | 622 | if(reduction(k,1,arr)==1){ 623 | count++; 624 | } 625 | if(reduction(k+1,2,arr)==1){ 626 | count++; 627 | } 628 | if(reduction(k+2,1,arr)==1){ 629 | count++; 630 | } 631 | if(count>max){ 632 | max=count; 633 | } 634 | } 635 | 636 | } 637 | } 638 | for(int k=0;k<7;k++){ 639 | for(int m=0;m<11;m++){ 640 | count=0; 641 | if(arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+2][m+1]==1){ 642 | 643 | if(reduction(k,1,arr)==1){ 644 | count++; 645 | } 646 | if(reduction(k+1,2,arr)==1){ 647 | count++; 648 | } 649 | if(reduction(k+2,1,arr)==1){ 650 | count++; 651 | } 652 | if(count>max){ 653 | max=count; 654 | } 655 | } 656 | } 657 | } 658 | ... 659 | public static int T(int[][] arr){ 660 | int count=0; 661 | int max=0; 662 | 663 | for(int k=0;k<7;k++){ 664 | for(int m=0;m<11;m++){ 665 | Genişlet 666 | message.txt 667 | 6 KB 668 | for(int k=0;k<8;k++){ 669 | for(int m=0;m<10;m++){ 670 | count=0; 671 | if(arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+1][m+2]==1){ 672 | 673 | if(reduction(k,1,arr)==1){ 674 | count++; 675 | } 676 | if(reduction(k+1,3,arr)==1){ 677 | count++; 678 | } 679 | if(count>max){ 680 | max=count; 681 | } 682 | } 683 | } 684 | } 685 | for(int k=0;k<8;k++){ 686 | for(int m=0;m<10;m++){ 687 | count=0; 688 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k][m+2]==1&&arr[k+1][m+1]==1){ 689 | 690 | if(reduction(k,3,arr)==1){ 691 | count++; 692 | } 693 | if(reduction(k+1,1,arr)==1){ 694 | count++; 695 | } 696 | if(count>max){ 697 | max=count; 698 | } 699 | } 700 | } 701 | } 702 | 703 | return max; 704 | } 705 | public static int Z(int[][] arr){ 706 | int count=0; 707 | int max=0; 708 | 709 | ... 710 | for(int k=0;k<8;k++){ 711 | for(int m=0;m<10;m++){ 712 | if(arr[k][m+1]==1&&arr[k][m+2]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1){ 713 | 714 | if(reduction(k,2,arr)==1){ 715 | count++; 716 | } 717 | if(reduction(k+1,2,arr)==1){ 718 | count++; 719 | } 720 | if(count>max){ 721 | max=count; 722 | } 723 | } 724 | 725 | } 726 | } 727 | for(int k=0;k<7;k++){ 728 | for(int m=0;m<11;m++){ 729 | count=0; 730 | if(arr[k][m]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+2][m+1]==1){ 731 | 732 | if(reduction(k,1,arr)==1){ 733 | count++; 734 | } 735 | if(reduction(k+1,2,arr)==1){ 736 | count++; 737 | } 738 | if(reduction(k+2,1,arr)==1){ 739 | count++; 740 | } 741 | if(count>max){ 742 | max=count; 743 | } 744 | } 745 | } 746 | } 747 | 748 | return max; 749 | } 750 | public static int reduction(int row, int ones,int[][] arr){ 751 | int one=0; 752 | int total=0; 753 | for(int i=0;i<12;i++){ 754 | total+=arr[row][i]; 755 | } 756 | if(total==ones){ 757 | one=1; 758 | } 759 | return one; 760 | } 761 | 762 | 763 | ... 764 | public static int ArrayChallenge(String[] strArr) { 765 | // code goes here 766 | int[][] arr= new int[9][12]; 767 | int result=0; 768 | StringBuilder sb= new StringBuilder(); 769 | for(int i=1;i<10;i++){ 770 | sb.delete(0,sb.length()); 771 | for(int j=1;j<13;j++){ 772 | 773 | if((Integer.parseInt(strArr[j])) 3 814 | 815 | 2.["I","2","4","3","4","5","2","0","2","2","3","3","3"] => 2 816 | 817 | 3.["T","4","3","2","3","5","2","0","1","2","4","3","4"] => 2 818 | 819 | 4.["S","4","3","2","3","5","2","0","1","2","4","3","4"] => 1 820 | 821 | 5.["O","4","3","2","3","5","1","0","1","2","4","3","4"] => 0 822 | 823 | 6.["T","4","3","2","3","2","1","0","1","2","4","3","4"] => 2 824 | 825 | 7.["I","4","3","3","4","2","0","0","1","3","4","3","4"] => 1 826 | 827 | 8.["Z","4","3","3","4","3","3","0","2","3","4","5","4"] => 2 828 | 829 | 9.["L","2","0","2","4","3","2","2","2","3","4","4","0"] => 0 830 | 831 | 1.["J","1","1","0","0","3","2","2","2","3","4","3","2"] => 1 832 | dilara — 24.11.2022 22:43 833 | import java.util.*; 834 | import java.io.*; 835 | 836 | class tetris { 837 | public static int I(int[][] arr){ 838 | int count=0; 839 | Genişlet 840 | tetris.java 841 | 14 KB 842 | Server Çetin — 01.12.2022 18:03 843 | Array Rotation 844 | Görsel 845 | yavvuz78 — 01.12.2022 18:04 846 | class Main { 847 | public static String ArrayChallenge(int[] arr) { 848 | int[] newArr=new int[arr.length]; 849 | String str=""; 850 | newArr[0]=arr[arr[0]]; 851 | for(int i=1;i list= new LinkedList(); 872 | int rotate = arr[0]; 873 | for(int i=rotate;i arrList = new ArrayList<>(); 940 | 941 | for(int i: arr){ 942 | arrList.add(i); 943 | } 944 | 945 | 946 | int rotateNum = arr[0]; 947 | 948 | for(int i=0; i cyc = new Stack(); 963 | String result = ""; 964 | for (int i=arr[0];i i) 987 | str1 += arr[i]; 988 | else 989 | str2 += arr[i]; 990 | } 991 | return str2 + str1 ; 992 | } 993 | 994 | public static String arrayChallenge2(int[] arr) { 995 | 996 | StringBuilder str1 = new StringBuilder(); 997 | StringBuilder str2 = new StringBuilder(); 998 | for (int i = 0 ; i < arr.length ; i++) { 999 | if(arr[0] > i) 1000 | str1.append(arr[i]); 1001 | else 1002 | str2.append(arr[i]); 1003 | } 1004 | return str2.toString() + str1 ; 1005 | } 1006 | 1007 | public static void main (String[] args) { 1008 | final List inputs = List.of( 1009 | new int[] {2, 3, 4, 1, 6, 10}, 1010 | new int[] {3,2,1,6}, 1011 | new int[] {4,3,4,3,1,2}, 1012 | new int[] {1,1,2}, 1013 | new int[] {0,1,2,3}, 1014 | new int[] {1,2,3,4,5}, 1015 | new int[] {6,2,4,4,4,4,4}, 1016 | new int[] {3,3,3,3,3}, 1017 | new int[] {4,3,2,1,5,6}, 1018 | new int[] {0,0} 1019 | ); 1020 | 1021 | final List results = List.of( 1022 | "4161023", 1023 | "6321", 1024 | "124343", 1025 | "121", 1026 | "0123", 1027 | "23451", 1028 | "4624444", 1029 | "33333", 1030 | "564321", 1031 | "00" 1032 | ); 1033 | 1034 | final Function function = ArrayRotation::arrayChallenge; 1035 | 1036 | out.println(inputs.stream().map(function).toList().equals(results)); 1037 | inputs.stream().map(function).forEach(out::println); 1038 | } 1039 | } 1040 | 1041 | Abdullah Taş — 01.12.2022 19:45 1042 | public static String ArrayChallenge(int[] arr) { 1043 | // code goes here 1044 | 1045 | int x = arr[0]; 1046 | String result=""; 1047 | for ( int i = x ; i list= new LinkedList(); 1071 | int rotate = arr[0]; 1072 | for(int i=rotate;i myList = new ArrayList(); 1107 | List newList = new ArrayList(); 1108 | List otherList = new ArrayList(); 1109 | int j=0; 1110 | 1111 | for (int i = 1; i < myStr.length() ; i++) { 1112 | 1113 | if (myStr.charAt(i - 1) != myStr.charAt(i)) { 1114 | myList.add(myStr.substring(j, i)); 1115 | j = i; 1116 | } 1117 | 1118 | } 1119 | myList.add(myStr.substring(j)); 1120 | 1121 | 1122 | 1123 | System.out.println(myList); 1124 | 1125 | 1126 | for(String i: myList){ 1127 | if(i.matches("[0-9]")){ 1128 | newList.add("$"); 1129 | otherList.add("$"); 1130 | } 1131 | else if(i.length()==1){ 1132 | newList.add("+"); 1133 | otherList.add("*{1}"); 1134 | } 1135 | else if(i.length()!=3){ 1136 | newList.add("*{"+String.valueOf(i.length())+"}"); 1137 | otherList.add("*{"+String.valueOf(i.length())+"}"); 1138 | } 1139 | else if(i.length()==3) { 1140 | newList.add("*"); 1141 | otherList.add("*"); 1142 | } 1143 | 1144 | } 1145 | String result=newList.toString().replace("[","").replace("]","").replaceAll(",","").replaceAll(" ",""); 1146 | String result1=otherList.toString().replace("[","").replace("]","").replaceAll(",","").replaceAll(" ",""); 1147 | System.out.println(result); 1148 | if(result.equals(strArr[0])||result1.equals(strArr[0])){ 1149 | return true; 1150 | } 1151 | return false; 1152 | } 1153 | 1154 | public static void main (String[] args) { 1155 | // keep this function call here 1156 | Scanner s = new Scanner(System.in); 1157 | System.out.print(StringChallenge(s.nextLine())); 1158 | } 1159 | 1160 | } 1161 | Server Çetin — 15.12.2022 18:14 1162 | 3 Number Encoding 1163 | Görsel 1164 | import java.util.*; import java.io.*; 1165 | 1166 | class Main { 1167 | 1168 | public static String StringChallenge(String str) { 1169 | // code goes here 1170 | String result=""; 1171 | str.toLowerCase(); 1172 | for(int i=0;i=0){ 1296 | result += index+1; 1297 | } 1298 | else{ 1299 | result +=arr[i]; 1300 | } 1301 | } 1302 | 1303 | return result; 1304 | } 1305 | Server Çetin — 22.12.2022 18:33 1306 | Step Walking 1307 | Görsel 1308 | Metin AKSU — 22.12.2022 19:00 1309 | public static int CombinatoricsChallenge(int num) { 1310 | if(num == 1 || num == 2) return num; 1311 | return CombinatoricsChallenge(num - 1) + CombinatoricsChallenge(num - 2); 1312 | } 1313 | Bu da ChatGPT'nin çözümü 1314 | public static int CombinatoricsChallenge2(int num) { 1315 | // Her basamak için tırmanma yollarını saklamak için bir dizi oluştur 1316 | int[] ways = new int[num + 1]; 1317 | // 0 basamak tırmanıldığında yol sayısı 1'tir (hiçbir şey yapma) 1318 | ways[0] = 1; 1319 | // 1 basamak tırmanıldığında yol sayısı 1'tir (1 adım atma) 1320 | ways[1] = 1; 1321 | // Geri kalan basamaklar için döngü oluştur 1322 | for (int i = 2; i <= num; i++) { 1323 | // i basamak tırmanıldığında yol sayısı, i - 1 basamak tırmanıldığında yol sayısına 1324 | // ve i - 2 basamak tırmanıldığında yol sayısına eşittir 1325 | ways[i] = ways[i - 1] + ways[i - 2]; 1326 | } 1327 | // Son basamak tırmanıldığında yol sayısını döndür (bu, basamak sayısıdır) 1328 | return ways[num]; 1329 | } 1330 | Fevzi Yüksel — 22.12.2022 19:03 1331 | Benim tepede memoizationlı bir tane vardı bulabilirsek bakarız 1332 | İzzet Ali Yıldırım — 22.12.2022 19:24 1333 | Görsel 1334 | Abdullah Taş — 22.12.2022 19:53 1335 | public static int CombinatoricsChallenge(int num) { 1336 | // Abdullah Tas 1337 | 1338 | if(num == 0 || num == 1 ) 1339 | return 1; 1340 | 1341 | return CombinatoricsChallenge(num-1) + CombinatoricsChallenge(num-2); 1342 | } 1343 | Abdullah Taş — 22.12.2022 19:54 1344 | 3. soru cevabı 1345 | https://youtu.be/jtM_RdkEzAM 1346 | YouTube 1347 | Abdullah Taş 1348 | Coderbyte Step Walking - JAVA 1349 | Görsel 1350 |  1351 | import java.util.*; import java.io.*; 1352 | 1353 | class Main { 1354 | public static int I(int[][] arr){ 1355 | int count=0; 1356 | int max=0; 1357 | for(int k=0;k<9;k++) { 1358 | for (int m = 3; m < 12; m++) { 1359 | if (arr[k][m - 3] == 1 && arr[k][m - 2] == 1 && arr[k][m - 1] == 1 && arr[k][m] == 1) { 1360 | if (reduction(k, 4, arr) == 1) { 1361 | max = 1; 1362 | } 1363 | } 1364 | } 1365 | } 1366 | for(int n=0;n<6;n++) { 1367 | for (int m = 0; m < 12; m++) { 1368 | if (arr[n][m] == 1 && arr[n + 1][m] == 1 && arr[n + 2][m] == 1 && arr[n + 3][m] == 1) { 1369 | count = 0; 1370 | if (reduction(n, 1, arr) == 1) { 1371 | count++; 1372 | } 1373 | if (reduction(n + 1, 1, arr) == 1) { 1374 | count++; 1375 | } 1376 | if (reduction(n + 2, 1, arr) == 1) { 1377 | count++; 1378 | } 1379 | if (reduction(n + 3, 1, arr) == 1) { 1380 | count++; 1381 | } 1382 | if (count > max) { 1383 | max = count; 1384 | } 1385 | } 1386 | } 1387 | } 1388 | return max; 1389 | } 1390 | public static int L(int[][] arr){ 1391 | int count=0; 1392 | int max=0; 1393 | for(int k=0;k<7;k++){ 1394 | for(int m=0;m<11;m++){ 1395 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+2][m]==1){ 1396 | 1397 | if(reduction(k,2,arr)==1){ 1398 | count++; 1399 | } 1400 | if(reduction(k+1,1,arr)==1){ 1401 | count++; 1402 | } 1403 | if(reduction(k+2,1,arr)==1){ 1404 | count++; 1405 | } 1406 | if(count>max){ 1407 | max=count; 1408 | } 1409 | } 1410 | 1411 | } 1412 | } 1413 | for(int k=0;k<7;k++){ 1414 | for(int m=0;m<11;m++){ 1415 | count=0; 1416 | if(arr[k][m+1]==1&&arr[k+1][m+1]==1&&arr[k+2][m]==1&&arr[k+2][m+1]==1){ 1417 | 1418 | if(reduction(k,1,arr)==1){ 1419 | count++; 1420 | } 1421 | if(reduction(k+1,1,arr)==1){ 1422 | count++; 1423 | } 1424 | if(reduction(k+2,2,arr)==1){ 1425 | count++; 1426 | } 1427 | if(count>max){ 1428 | max=count; 1429 | } 1430 | } 1431 | } 1432 | } 1433 | for(int k=0;k<8;k++){ 1434 | for(int m=0;m<10;m++){ 1435 | count=0; 1436 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k][m+2]==1&&arr[k+1][m+2]==1){ 1437 | 1438 | if(reduction(k,3,arr)==1){ 1439 | count++; 1440 | } 1441 | if(reduction(k+1,1,arr)==1){ 1442 | count++; 1443 | } 1444 | if(count>max){ 1445 | max=count; 1446 | } 1447 | } 1448 | } 1449 | } 1450 | for(int k=0;k<8;k++){ 1451 | for(int m=0;m<10;m++){ 1452 | count=0; 1453 | if(arr[k][m]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+1][m+2]==1){ 1454 | 1455 | if(reduction(k,1,arr)==1){ 1456 | count++; 1457 | } 1458 | if(reduction(k+1,3,arr)==1){ 1459 | count++; 1460 | } 1461 | if(count>max){ 1462 | max=count; 1463 | } 1464 | } 1465 | } 1466 | } 1467 | return max; 1468 | } 1469 | public static int J(int[][] arr){ 1470 | int count=0; 1471 | int max=0; 1472 | 1473 | for(int k=0;k<7;k++){ 1474 | for(int m=0;m<11;m++){ 1475 | if(arr[k][m]==1&&arr[k+1][m]==1&&arr[k+2][m]==1&&arr[k+2][m+1]==1){ 1476 | 1477 | if(reduction(k,1,arr)==1){ 1478 | count++; 1479 | } 1480 | if(reduction(k+1,1,arr)==1){ 1481 | count++; 1482 | } 1483 | if(reduction(k+2,2,arr)==1){ 1484 | count++; 1485 | } 1486 | if(count>max){ 1487 | max=count; 1488 | } 1489 | } 1490 | 1491 | } 1492 | } 1493 | for(int k=0;k<7;k++){ 1494 | for(int m=0;m<11;m++){ 1495 | count=0; 1496 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k+1][m+1]==1&&arr[k+2][m+1]==1){ 1497 | 1498 | if(reduction(k,2,arr)==1){ 1499 | count++; 1500 | } 1501 | if(reduction(k+1,1,arr)==1){ 1502 | count++; 1503 | } 1504 | if(reduction(k+2,1,arr)==1){ 1505 | count++; 1506 | } 1507 | if(count>max){ 1508 | max=count; 1509 | } 1510 | } 1511 | } 1512 | } 1513 | for(int k=0;k<8;k++){ 1514 | for(int m=0;m<10;m++){ 1515 | count=0; 1516 | if(arr[k][m+2]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+1][m+2]==1){ 1517 | 1518 | if(reduction(k,1,arr)==1){ 1519 | count++; 1520 | } 1521 | if(reduction(k+1,3,arr)==1){ 1522 | count++; 1523 | } 1524 | if(count>max){ 1525 | max=count; 1526 | } 1527 | } 1528 | } 1529 | } 1530 | for(int k=0;k<8;k++){ 1531 | for(int m=0;m<10;m++){ 1532 | count=0; 1533 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k][m+2]==1&&arr[k+1][m]==1){ 1534 | 1535 | if(reduction(k,3,arr)==1){ 1536 | count++; 1537 | } 1538 | if(reduction(k+1,1,arr)==1){ 1539 | count++; 1540 | } 1541 | if(count>max){ 1542 | max=count; 1543 | } 1544 | } 1545 | } 1546 | } 1547 | 1548 | return max; 1549 | } 1550 | public static int O(int[][] arr){ 1551 | int count=0; 1552 | int max=0; 1553 | 1554 | for(int k=0;k<8;k++){ 1555 | for(int m=0;m<11;m++){ 1556 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1){ 1557 | 1558 | if(reduction(k,2,arr)==1){ 1559 | count++; 1560 | } 1561 | if(reduction(k+1,2,arr)==1){ 1562 | count++; 1563 | } 1564 | if(count>max){ 1565 | max=count; 1566 | } 1567 | } 1568 | 1569 | } 1570 | } 1571 | return max; 1572 | 1573 | } 1574 | public static int S(int[][] arr){ 1575 | int count=0; 1576 | int max=0; 1577 | 1578 | for(int k=0;k<8;k++){ 1579 | for(int m=0;m<10;m++){ 1580 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k+1][m+1]==1&&arr[k+1][m+2]==1){ 1581 | 1582 | if(reduction(k,2,arr)==1){ 1583 | count++; 1584 | } 1585 | if(reduction(k+1,2,arr)==1){ 1586 | count++; 1587 | } 1588 | if(count>max){ 1589 | max=count; 1590 | } 1591 | } 1592 | 1593 | } 1594 | } 1595 | for(int k=0;k<7;k++){ 1596 | for(int m=0;m<11;m++){ 1597 | count=0; 1598 | if(arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+2][m]==1){ 1599 | 1600 | if(reduction(k,1,arr)==1){ 1601 | count++; 1602 | } 1603 | if(reduction(k+1,2,arr)==1){ 1604 | count++; 1605 | } 1606 | if(reduction(k+2,1,arr)==1){ 1607 | count++; 1608 | } 1609 | if(count>max){ 1610 | max=count; 1611 | } 1612 | } 1613 | } 1614 | } 1615 | return max; 1616 | } 1617 | public static int T(int[][] arr){ 1618 | int count=0; 1619 | int max=0; 1620 | 1621 | for(int k=0;k<7;k++){ 1622 | for(int m=0;m<11;m++){ 1623 | if(arr[k][m]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+2][m]==1){ 1624 | 1625 | if(reduction(k,1,arr)==1){ 1626 | count++; 1627 | } 1628 | if(reduction(k+1,2,arr)==1){ 1629 | count++; 1630 | } 1631 | if(reduction(k+2,1,arr)==1){ 1632 | count++; 1633 | } 1634 | if(count>max){ 1635 | max=count; 1636 | } 1637 | } 1638 | 1639 | } 1640 | } 1641 | for(int k=0;k<7;k++){ 1642 | for(int m=0;m<11;m++){ 1643 | count=0; 1644 | if(arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+2][m+1]==1){ 1645 | 1646 | if(reduction(k,1,arr)==1){ 1647 | count++; 1648 | } 1649 | if(reduction(k+1,2,arr)==1){ 1650 | count++; 1651 | } 1652 | if(reduction(k+2,1,arr)==1){ 1653 | count++; 1654 | } 1655 | if(count>max){ 1656 | max=count; 1657 | } 1658 | } 1659 | } 1660 | } 1661 | for(int k=0;k<8;k++){ 1662 | for(int m=0;m<10;m++){ 1663 | count=0; 1664 | if(arr[k][m+1]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+1][m+2]==1){ 1665 | 1666 | if(reduction(k,1,arr)==1){ 1667 | count++; 1668 | } 1669 | if(reduction(k+1,3,arr)==1){ 1670 | count++; 1671 | } 1672 | if(count>max){ 1673 | max=count; 1674 | } 1675 | } 1676 | } 1677 | } 1678 | for(int k=0;k<8;k++){ 1679 | for(int m=0;m<10;m++){ 1680 | count=0; 1681 | if(arr[k][m]==1&&arr[k][m+1]==1&&arr[k][m+2]==1&&arr[k+1][m+1]==1){ 1682 | 1683 | if(reduction(k,3,arr)==1){ 1684 | count++; 1685 | } 1686 | if(reduction(k+1,1,arr)==1){ 1687 | count++; 1688 | } 1689 | if(count>max){ 1690 | max=count; 1691 | } 1692 | } 1693 | } 1694 | } 1695 | 1696 | return max; 1697 | } 1698 | public static int Z(int[][] arr){ 1699 | int count=0; 1700 | int max=0; 1701 | 1702 | for(int k=0;k<8;k++){ 1703 | for(int m=0;m<10;m++){ 1704 | if(arr[k][m+1]==1&&arr[k][m+2]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1){ 1705 | 1706 | if(reduction(k,2,arr)==1){ 1707 | count++; 1708 | } 1709 | if(reduction(k+1,2,arr)==1){ 1710 | count++; 1711 | } 1712 | if(count>max){ 1713 | max=count; 1714 | } 1715 | } 1716 | 1717 | } 1718 | } 1719 | for(int k=0;k<7;k++){ 1720 | for(int m=0;m<11;m++){ 1721 | count=0; 1722 | if(arr[k][m]==1&&arr[k+1][m]==1&&arr[k+1][m+1]==1&&arr[k+2][m+1]==1){ 1723 | 1724 | if(reduction(k,1,arr)==1){ 1725 | count++; 1726 | } 1727 | if(reduction(k+1,2,arr)==1){ 1728 | count++; 1729 | } 1730 | if(reduction(k+2,1,arr)==1){ 1731 | count++; 1732 | } 1733 | if(count>max){ 1734 | max=count; 1735 | } 1736 | } 1737 | } 1738 | } 1739 | 1740 | return max; 1741 | } 1742 | public static int reduction(int row, int ones,int[][] arr){ 1743 | int one=0; 1744 | int total=0; 1745 | for(int i=0;i<12;i++){ 1746 | total+=arr[row][i]; 1747 | } 1748 | if(total==ones){ 1749 | one=1; 1750 | } 1751 | return one; 1752 | } 1753 | 1754 | 1755 | public static int ArrayChallenge(String[] strArr) { 1756 | // code goes here 1757 | int[][] arr= new int[9][12]; 1758 | int result=0; 1759 | StringBuilder sb= new StringBuilder(); 1760 | for(int i=1;i<10;i++){ 1761 | sb.delete(0,sb.length()); 1762 | for(int j=1;j<13;j++){ 1763 | 1764 | if((Integer.parseInt(strArr[j]))> graph = new HashMap<>(); 8 | for (int i = n + 1; i < strArr.length; i++) { 9 | String[] edge = strArr[i].split("\\|"); 10 | String from = edge[0]; 11 | String to = edge[1]; 12 | int weight = Integer.parseInt(edge[2]); 13 | graph.putIfAbsent(from, new HashMap<>()); 14 | graph.putIfAbsent(to, new HashMap<>()); 15 | graph.get(from).put(to, weight); 16 | graph.get(to).put(from, weight); 17 | } 18 | Map dist = new HashMap<>(); 19 | Map prev = new HashMap<>(); 20 | for (String node : nodes) { 21 | dist.put(node, Integer.MAX_VALUE); 22 | prev.put(node, null); 23 | } 24 | dist.put(nodes[0], 0); 25 | PriorityQueue pq = new PriorityQueue<>(Comparator.comparingInt(dist::get)); 26 | pq.add(nodes[0]); 27 | while (!pq.isEmpty()) { 28 | String node = pq.poll(); 29 | if (node.equals(nodes[n - 1])) { 30 | break; 31 | } 32 | try{ 33 | for (Map.Entry entry : graph.get(node).entrySet()) { 34 | String neighbor = entry.getKey(); 35 | int weight = entry.getValue(); 36 | int newDist = dist.get(node) + weight; 37 | if (newDist < dist.get(neighbor)) { 38 | dist.put(neighbor, newDist); 39 | prev.put(neighbor, node); 40 | pq.add(neighbor); 41 | } 42 | } 43 | 44 | }catch (NullPointerException e){ 45 | return "-1"; 46 | } 47 | 48 | } 49 | if (dist.get(nodes[n - 1]) == Integer.MAX_VALUE) { 50 | return "-1"; 51 | } 52 | StringBuilder sb = new StringBuilder(); 53 | String node = nodes[n - 1]; 54 | while (node != null) { 55 | sb.insert(0, node); 56 | node = prev.get(node); 57 | if (node != null) { 58 | sb.insert(0, "-"); 59 | } 60 | } 61 | return sb.toString(); 62 | } 63 | -------------------------------------------------------------------------------- /Hard/WildcardCharacters.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | 3 | public static boolean WildcardCharacters(String str) { 4 | 5 | boolean sonuc=true; 6 | int sayac=0; 7 | 8 | int a= str.indexOf(" "); // boşluk olan yeri bulurum 9 | String str1 = str.substring(0,a); // kelimeleri ayırırım 10 | String str2 = str.substring(a+1,str.length()); 11 | 12 | 13 | 14 | for ( int i =0 ; isayac){ /* str1 deki karekter bitmesine rağmen str2 de karekter elle kurduğum 97 | sayactan hala uzun ise fazlaadan karekter var demektir buda sonucu false yapar */ 98 | 99 | sonuc=false; 100 | 101 | } 102 | 103 | return sonuc ? true : false; // ne programdı ama :)) 104 | 105 | } 106 | 107 | public static void main (String[] args) { 108 | // keep this function call here 109 | Scanner s = new Scanner(System.in); 110 | System.out.print(WildcardCharacters(s.nextLine())); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /Hard/Wildcards.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static boolean StringChallenge(String str) { 7 | // code goes here 8 | String[] strArr= str.split(" "); 9 | String myStr =strArr[1]; 10 | List myList = new ArrayList(); 11 | List newList = new ArrayList(); 12 | List otherList = new ArrayList(); 13 | int j=0; 14 | 15 | for (int i = 1; i < myStr.length() ; i++) { 16 | 17 | if (myStr.charAt(i - 1) != myStr.charAt(i)) { 18 | myList.add(myStr.substring(j, i)); 19 | j = i; 20 | } 21 | 22 | } 23 | myList.add(myStr.substring(j)); 24 | 25 | 26 | 27 | System.out.println(myList); 28 | 29 | 30 | for(String i: myList){ 31 | if(i.matches("[0-9]")){ 32 | newList.add("$"); 33 | otherList.add("$"); 34 | } 35 | else if(i.length()==1){ 36 | newList.add("+"); 37 | otherList.add("*{1}"); 38 | } 39 | else if(i.length()!=3){ 40 | newList.add("*{"+String.valueOf(i.length())+"}"); 41 | otherList.add("*{"+String.valueOf(i.length())+"}"); 42 | } 43 | else if(i.length()==3) { 44 | newList.add("*"); 45 | otherList.add("*"); 46 | } 47 | 48 | } 49 | String result=newList.toString().replace("[","").replace("]","").replaceAll(",","").replaceAll(" ",""); 50 | String result1=otherList.toString().replace("[","").replace("]","").replaceAll(",","").replaceAll(" ",""); 51 | System.out.println(result); 52 | if(result.equals(strArr[0])||result1.equals(strArr[0])){ 53 | return true; 54 | } 55 | return false; 56 | } 57 | 58 | public static void main (String[] args) { 59 | // keep this function call here 60 | Scanner s = new Scanner(System.in); 61 | System.out.print(StringChallenge(s.nextLine())); 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /Medium/ArithGeoII.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String ArithGeoII(int[] arr) { 7 | double ratio=arr[1]/arr[0]; 8 | int difference=arr[1]-arr[0]; 9 | String arithgeo=""; 10 | for(int i=1;i> index = new ArrayList>(); 7 | ArrayList> mat = new ArrayList>(); 8 | int holes = 0; 9 | boolean checker; 10 | 11 | for(int i = 0; i < strArr.length; i++){ 12 | mat.add(new ArrayList(Arrays.asList(strArr[i].split("")))); 13 | for(int j = 0; j < strArr[i].length(); j++){ 14 | if(mat.get(i).get(j).equals("0")) { 15 | index.add(new ArrayList(Arrays.asList(i,j))); 16 | } 17 | } 18 | } 19 | 20 | for(int c = 0; c < index.size(); c++){ 21 | checker = false; 22 | for(int k = c+1; k < index.size(); k++){ 23 | if(index.get(k).get(0) == index.get(c).get(0)+1 && 24 | index.get(k).get(1) == index.get(c).get(1) || 25 | index.get(k).get(0) == index.get(c).get(0) && 26 | index.get(k).get(1) == index.get(c).get(1) + 1) 27 | checker = true; 28 | } 29 | if(checker == false) holes++; 30 | } 31 | return String.valueOf(holes); 32 | } 33 | public static void main (String[] args) { 34 | // keep this function call here 35 | Scanner s = new Scanner(System.in); 36 | System.out.print(BitmapHoles(s.nextLine())); 37 | } 38 | } -------------------------------------------------------------------------------- /Medium/BracketMatcher.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String BracketMatcher(String str) { 7 | 8 | if(!str.contains("(") && !str.contains(")")) 9 | return "1"; 10 | 11 | Stack stack = new Stack(); 12 | String[] strArray = str.split(""); 13 | 14 | for(int i=0; i < strArray.length; i++){ 15 | 16 | String x = strArray[i]; 17 | 18 | if(x.equals("(")) 19 | stack.push(x); 20 | 21 | if(x.equals(")")){ 22 | if(stack.isEmpty()) 23 | return "0"; 24 | 25 | String y = stack.peek(); 26 | if(x.equals(")") && y.equals("(")){ 27 | stack.pop(); 28 | }else{ 29 | return "0"; 30 | } 31 | } 32 | } 33 | 34 | if(stack.isEmpty()) 35 | return "1"; 36 | else 37 | return "0"; 38 | } 39 | 40 | public static void main (String[] args) { 41 | // keep this function call here 42 | Scanner s = new Scanner(System.in); 43 | System.out.print(BracketMatcher(s.nextLine())); 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /Medium/CaesarCipher.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String CaesarCipher(String str, int num) { 7 | // code goes here 8 | int code, newCode; 9 | String result = "", newChar; 10 | 11 | for (int i = 0; i < str.length(); i++) { 12 | code = (int) str.charAt(i); 13 | newCode = code + num; 14 | 15 | if (code >= 65 && code <= 90) { 16 | if (newCode > 90) newCode = 64 + (newCode - 90); 17 | } 18 | else if (code >= 97 && code <= 122) { 19 | if (newCode > 122) newCode = 96 + (newCode - 122); 20 | } 21 | else { 22 | newCode = code; 23 | } 24 | 25 | newChar = String.valueOf((char) newCode); 26 | result += newChar; 27 | } 28 | return result; 29 | } 30 | 31 | public static void main (String[] args) { 32 | // keep this function call here 33 | Scanner s = new Scanner(System.in); 34 | System.out.print(CaesarCipher(s.nextLine())); 35 | } 36 | } -------------------------------------------------------------------------------- /Medium/Consecutive.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | import java.util.Arrays; 4 | 5 | class Main { 6 | 7 | public static int Consecutive(int[] arr) { 8 | // code goes here 9 | Arrays.sort(arr); 10 | 11 | int amount = 0; 12 | for (int i = 1; i < arr.length; i++) { 13 | amount += Math.abs(arr[i] - arr[i - 1]) - 1; 14 | } 15 | return amount; 16 | } 17 | 18 | public static void main (String[] args) { 19 | // keep this function call here 20 | Scanner s = new Scanner(System.in); 21 | System.out.print(Consecutive(s.nextLine())); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Medium/CountingMinutes.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int CountingMinutes(String str) { 7 | String[] time = str.split("-"); 8 | 9 | String[] firstTime = time[0].split(":"); 10 | int firstHour = Integer.parseInt(firstTime[0]); 11 | int firstMin = extractMin(firstTime[1]); 12 | String firstPeriod = extractPeriod(firstTime[1]); 13 | 14 | String[] secondTime = time[1].split(":"); 15 | int secondHour = Integer.parseInt(secondTime[0]); 16 | int secondMin = extractMin(secondTime[1]); 17 | String secondPeriod = extractPeriod(secondTime[1]); 18 | 19 | if(!firstPeriod.equals(secondPeriod)){ 20 | return (12-firstHour)*60 + (60-firstMin) + (secondHour-1)*60 + secondMin; 21 | } 22 | else{ 23 | if((firstHour > secondHour) || ((firstHour == secondHour) && (firstMin > secondMin))){ 24 | return (24-firstHour)*60 + (60-firstMin) + (secondHour-1)*60 + secondMin; 25 | } 26 | else{ 27 | return (secondHour-(firstHour+1))*60 + (60-firstMin)+secondMin ; 28 | } 29 | } 30 | } 31 | public static String extractPeriod(String time){ 32 | String period = ""; 33 | period = time.substring(2); 34 | return period; 35 | 36 | } 37 | public static int extractMin(String time){ 38 | String min = ""; 39 | min = time.substring(0,2); 40 | return Integer.parseInt(min); 41 | } 42 | 43 | public static void main (String[] args) { 44 | // keep this function call here 45 | Scanner s = new Scanner(System.in); 46 | System.out.print(CountingMinutes(s.nextLine())); 47 | } 48 | } -------------------------------------------------------------------------------- /Medium/DistinctList.java: -------------------------------------------------------------------------------- 1 | import java.util.; 2 | import java.io.; 3 | 4 | class Main { 5 | 6 | public static int DistinctList(int[] arr) { 7 | Arrays.sort(arr); 8 | int counter = 0; 9 | 10 | for (int i = 1; i < arr.length; i++) { 11 | if (arr[i - 1] == arr[i]) { 12 | counter++; 13 | } 14 | } 15 | return counter; 16 | } 17 | 18 | public static void main (String[] args) { 19 | //keep this function call here 20 | Scanner s = new Scanner(System.in); 21 | System.out.print(DistinctList(s.nextLine())); 22 | } 23 | } -------------------------------------------------------------------------------- /Medium/Division.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int MathChallenge(int n1, int n2) { 7 | while(n1 != n2){ 8 | if(n1>n2) 9 | n1 -= n2; 10 | else 11 | n2 -= n1; 12 | } 13 | 14 | return n1; 15 | } 16 | 17 | public static void main (String[] args) { 18 | // keep this function call here 19 | Scanner s = new Scanner(System.in); 20 | System.out.print(MathChallenge(s.nextLine())); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /Medium/EvenPairs.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static boolean EvenPairs(String str) { 7 | // code goes here 8 | char[] characters = str.toCharArray(); 9 | int length = characters.length; 10 | int counter = 0; 11 | int evenCounter = 0; 12 | 13 | for(int i=0; i 1 && isEven) { 27 | return true; 28 | } 29 | } 30 | 31 | return false; 32 | } 33 | 34 | static int getDigit(char ch) { 35 | return Character.getNumericValue(ch); 36 | } 37 | 38 | static boolean isDigit(char ch) { 39 | if (Character.isDigit(ch)) { 40 | return true; 41 | } 42 | return false; 43 | } 44 | 45 | static boolean isEven(int n) { 46 | if (n % 2 == 0) { 47 | return true; 48 | } 49 | return false; 50 | } 51 | 52 | public static void main (String[] args) { 53 | // keep this function call here 54 | Scanner s = new Scanner(System.in); 55 | System.out.print(EvenPairs(s.nextLine())); 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /Medium/FibonacciChecker.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String FibonacciChecker(int num) { 7 | int fib1 = 0; 8 | int fib2 = 1; 9 | do { 10 | int saveFib1 = fib1; 11 | fib1 = fib2; 12 | fib2 = saveFib1 + fib2; 13 | } 14 | while (fib2 < num); 15 | if (fib2 == num) { 16 | return "yes"; 17 | } else { 18 | return "no"; 19 | } 20 | 21 | } 22 | 23 | public static void main (String[] args) { 24 | // keep this function call here 25 | Scanner s = new Scanner(System.in); 26 | System.out.print(FibonacciChecker(s.nextLine())); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Medium/FormattedDivision.java: -------------------------------------------------------------------------------- 1 | import java.util.; 2 | import java.io.; 3 | 4 | class Main { 5 | 6 | public static String FormattedDivision(int num1, int num2) { 7 | // code goes here 8 | double division = num1 * 1.00 / num2; 9 | return String.format("%,.4f", division); 10 | } 11 | 12 | public static void main (String[] args) { 13 | // keep this function call here 14 | Scanner s = new Scanner(System.in); 15 | System.out.print(FormattedDivision(s.nextLine())); 16 | } 17 | } -------------------------------------------------------------------------------- /Medium/FormattedNumber.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String StringChallenge(String str) { 7 | 8 | String newstr=""; 9 | 10 | for ( int i = 0 ; i < str.length() ; i++){ 11 | 12 | char letter = str.charAt(i); 13 | 14 | if ( letter >= 'a' && letter <= 'z' || letter >= 'A' && letter <='Z'){ 15 | 16 | if ( isControl(newstr,letter)) newstr += letter; 17 | } 18 | } 19 | 20 | return newstr.length() == 26 ? "true" : "false"; 21 | 22 | } 23 | 24 | public static boolean isControl (String str, char x){ 25 | 26 | for (int i =0 ; i]"); 31 | ArrayList arrList= new ArrayList(); 32 | Stack stack= new Stack(); 33 | for(String s: strArr){ 34 | for(String[] array: taken){ 35 | if(s.equals(array[0])||s.equals(array[1])){ 36 | arrList.add(s); 37 | 38 | } 39 | 40 | } 41 | } 42 | 43 | if(arrList.size()==1){ 44 | return arrList.get(0); 45 | } 46 | 47 | for(int i=0;i> permute(int[] nums){ 7 | List> result = new ArrayList<>(); 8 | Permutation(0,nums,result); 9 | return result; 10 | } 11 | 12 | 13 | public static void Permutation(int i,int[]nums,List> result){ 14 | if(i == nums.length-1){ 15 | List list = new ArrayList<>(); 16 | for(int n: nums) list.add(n); 17 | result.add(list); 18 | }else{ 19 | for(int j = i,l= nums.length;j arr){ 50 | int ans = arr.get(0); 51 | for(int i = 1; i> array = permute(myArray); 66 | //System.out.print(concatenateArr(array.get(4))); 67 | //System.out.print(array); 68 | for(int i=0;i arlist = new ArrayList(); 9 | for(int i=0;imax){ 22 | max=sum; 23 | } 24 | } 25 | 26 | } 27 | 28 | } 29 | 30 | return max; 31 | } 32 | 33 | public static void main (String[] args) { 34 | // keep this function call here 35 | Scanner s = new Scanner(System.in); 36 | System.out.print(MaxSubarray(s.nextLine())); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Medium/MaxtrixSpiral.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String MatrixSpiral(String[] strArr) { 7 | // code goes here 8 | int xSize = 0; 9 | int ySize = 0; 10 | xSize = strArr.length; 11 | ySize = strArr[0].replace("[","").replace("]","").replace(" ","").split(",").length; 12 | 13 | int[][] numArr = new int[xSize][ySize]; 14 | for (int i = 0; i < xSize; i++) { 15 | strArr[i] = strArr[i].replace("[","").replace("]","").replace(" ",""); 16 | String[] newArr = strArr[i].split(","); 17 | 18 | for (int k = 0; k < ySize; k++) { 19 | numArr[i][k] = Integer.parseInt(newArr[k]); 20 | } 21 | } 22 | 23 | int direction = 0; 24 | int top = 0, bottom = xSize - 1, left = 0, right = ySize - 1; 25 | String result = ""; 26 | 27 | while (top <= bottom && left <= right) { 28 | if (direction == 0) { 29 | for (int i = left; i <= right; i++) { 30 | if (result.length() == 0) { 31 | result += numArr[top][i]; 32 | } else { 33 | result += "," + numArr[top][i]; 34 | } 35 | } 36 | top++; 37 | } else if (direction == 1) { 38 | for (int i = top; i <= bottom; i++) { 39 | result += "," + numArr[i][right]; 40 | } 41 | right--; 42 | } else if (direction == 2) { 43 | for (int i = right; i >= left; i--) { 44 | result += "," + numArr[bottom][i]; 45 | } 46 | bottom--; 47 | } else if (direction == 3) { 48 | for (int i = bottom; i >= top; i--) { 49 | result += "," + numArr[i][left]; 50 | } 51 | left++; 52 | } 53 | direction = (direction + 1) % 4; 54 | } 55 | return result; 56 | } 57 | 58 | public static void main (String[] args) { 59 | // keep this function call here 60 | Scanner s = new Scanner(System.in); 61 | System.out.print(MatrixSpiral(s.nextLine())); 62 | } 63 | } -------------------------------------------------------------------------------- /Medium/NearestSmallerValues.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int[] NearestSmallerValues(int[] arr) { 7 | int[] newArr = new int[arr.length]; 8 | for (int i = 0; i < arr.length; i++) { 9 | int num = -1; 10 | 11 | for (int j = i - 1; j >= 0; j--) { 12 | if (arr[j] < arr[i] || arr[j] == arr[i]){ 13 | num = arr[j]; 14 | break; 15 | } 16 | } 17 | newArr[i] = num; 18 | } 19 | return newArr; 20 | } 21 | 22 | public static void main (String[] args) { 23 | Scanner s = new Scanner(System.in); 24 | int[] arr = NearestSmallerValues(s.nextLine()); 25 | for (int a : arr) System.out.print(a + " "); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Medium/NumberSearch.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int NumberSearch(String str) { 7 | // code goes here 8 | double countLetter=0; 9 | double sumTotal=0; 10 | int result=0; 11 | for(int i=0;i= 1; j--) { 12 | if (i % j == 0) 13 | counter++; 14 | } 15 | if (counter == 2) 16 | count++; 17 | 18 | if (count == num) 19 | return i; 20 | } 21 | return -1; 22 | } 23 | 24 | public static void main (String[] args) { 25 | // keep this function call here 26 | Scanner s = new Scanner(System.in); 27 | System.out.print(PrimeMover(s.nextLine())); 28 | } 29 | } -------------------------------------------------------------------------------- /Medium/PrimeTime.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | 7 | public static boolean PrimeTime(int num) { 8 | //code goes here 9 | if(num <= 1) { 10 | return false; 11 | } 12 | if(num == 2) { 13 | return true; 14 | } 15 | if(num % 2 == 0) { 16 | return false; 17 | } 18 | for(int i = 3 ; i < num ; i += 2){ 19 | if(num % i == 0){ 20 | return false; 21 | } 22 | } 23 | return true; 24 | } 25 | 26 | public static void main (String[] args) { 27 | // keep this function call here 28 | Scanner s = new Scanner(System.in); 29 | System.out.print(PrimeTime(s.nextLine())); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Medium/Primes.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | public static boolean Primes(int num) { 6 | boolean isPrime = true; 7 | if (num >= i && num <= Math.pow(2,16)) { 8 | for (int i = 2; i < num; i++) { 9 | if (num % i == 0) { 10 | isPrime == false; 11 | break; 12 | } 13 | } 14 | } 15 | return isPrime; 16 | } 17 | 18 | public static void main (String[] args) { 19 | //keep this function call here 20 | Scanner s = new Scanner(System.in); 21 | System.out.print(Primes(s.nextLine())); 22 | } 23 | } -------------------------------------------------------------------------------- /Medium/RunLength.java: -------------------------------------------------------------------------------- 1 | import java.util.; 2 | import java.io.; 3 | 4 | class Main { 5 | 6 | public static String RunLength(String str) { 7 | // code goes here 8 | String repost = ""; 9 | int count = 1; 10 | char c = str.charAt(0); 11 | for(int i=1; i maxCounter) { 19 | maxCounter = counter; 20 | mResult = arr[i]; 21 | } 22 | } 23 | 24 | if (maxCounter == 1) { 25 | return -1; 26 | } 27 | else { 28 | return mResult; 29 | } 30 | } 31 | 32 | public static void main (String[] args) { 33 | // keep this function call here 34 | Scanner s = new Scanner(System.in); 35 | System.out.print(SimpleMode(s.nextLine())); 36 | } 37 | } -------------------------------------------------------------------------------- /Medium/StarRating.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String StringChallenge(String str) { 7 | // code goes here 8 | float value = Float.parseFloat(str); 9 | int starCount = 0; 10 | String sonuc=""; 11 | 12 | while(starCount < 5){ 13 | if(value >= 1){ 14 | sonuc+="full "; 15 | 16 | value-=1; 17 | } 18 | else if(value > 0){ 19 | if(value+.25 >= 1){ 20 | sonuc+="full "; 21 | } 22 | else if(value+.25 >= .5){ 23 | sonuc+="half "; 24 | } 25 | else{ 26 | sonuc+="empty "; 27 | } 28 | value-=value; 29 | } 30 | else{ 31 | sonuc+="empty "; 32 | } 33 | starCount++; 34 | } 35 | 36 | return sonuc; 37 | } 38 | 39 | public static void main (String[] args) { 40 | // keep this function call here 41 | Scanner s = new Scanner(System.in); 42 | String str; 43 | str = s.nextLine(); 44 | System.out.print(StringChallenge(str)); 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /Medium/StockPicker.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int StockPicker(int[] arr) { 7 | // code goes here 8 | int result=0; 9 | 10 | for ( int i = 0 ; i result) result = arr[j]-arr[i]; 14 | } 15 | 16 | } 17 | return result == 0 ? -1 : result; 18 | } 19 | 20 | public static void main (String[] args) { 21 | // keep this function call here 22 | Scanner s = new Scanner(System.in); 23 | System.out.print(StockPicker(s.nextLine())); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Medium/StringReduction.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int StringReduction(String str) { 7 | // code goes here 8 | int a=0,b=0,c=0; 9 | 10 | for (int i =0 ; i freq = new HashSet<>(); 7 | 8 | public static void CountMultiples (int num, int mp) { 9 | for (int i = mp; i < num; i += mp) { 10 | if (i% mp == 0) { 11 | freq.add(i); 12 | } 13 | } 14 | } 15 | 16 | public static int ThreeFiveMultiples(int num) { 17 | 18 | int total = 0; 19 | CountMultiples(num, 3); 20 | CountMultiples(num, 5); 21 | for (int i: freq) { 22 | total += i; 23 | } 24 | return total; 25 | } 26 | 27 | public static void main (String[] args) { 28 | //keep this function call here 29 | Scanner s = new Scanner(System.in); 30 | System.out.print(ThreeFiveMultiples(s.nextLine())); 31 | } 32 | } -------------------------------------------------------------------------------- /Medium/TrappingWater.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static int TrappingWater(int[] arr) { 7 | // code goes here 8 | ArrayList tw = new ArrayList(); 9 | for(int i=0;itemp){ 30 | temp=sum; 31 | } 32 | } 33 | } 34 | } 35 | return temp; 36 | } 37 | 38 | public static void main (String[] args) { 39 | // keep this function call here 40 | Scanner s = new Scanner(System.in); 41 | System.out.print(TrappingWater(s.nextLine())); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Medium/WordSplit.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Main { 5 | 6 | public static String ArrayChallenge(String[] strArr) { 7 | // code goes here 8 | String output="not possible"; 9 | String otherHalf=""; 10 | String word = strArr[0]; 11 | String[] secondElement = strArr[1].split(","); 12 | 13 | for(int i= 0; i