├── .gitignore ├── 01-flow-of-program └── 01-flow-of-program.md ├── 02-first-java ├── 02-first-java.md ├── Calculator.java ├── ContinuousSum.java ├── CurrencyConverter.java ├── EvenOdd.java ├── Factorial.java ├── Factors.java ├── Greeting.java ├── LargestNumContinuous.java ├── LargestNumber.java └── SimpleInterest.java ├── 03-conditionals-loops ├── 03-conditionals-loops.md └── basic │ ├── AreaOfCircle.java │ ├── AreaOfEquilateralTriangle.java │ ├── AreaOfIsoscelesTriangle.java │ ├── AreaOfParallelogram.java │ ├── AreaOfRectangle.java │ ├── AreaOfRhombus.java │ ├── AreaOfTriangle.java │ ├── CSAOfCylinder.java │ ├── DiffOfSDnPD.java │ ├── FibonacciSeries.java │ ├── PerimeterOfCircle.java │ ├── PerimeterOfEquilateralTriangle.java │ ├── PerimeterOfParallelogram.java │ ├── PerimeterOfRectangle.java │ ├── PerimeterOfSquare.java │ ├── TSAOfCube.java │ ├── VolumeOfCone.java │ ├── VolumeOfCylinder.java │ ├── VolumeOfPrism.java │ ├── VolumeOfPyramid.java │ └── VolumeOfSphere.java ├── 04-functions └── 04-functions.md ├── 05-arrays ├── 05-arrays.md ├── Medium │ ├── FirstLast.java │ ├── JumpGame.java │ ├── ProductArray.java │ ├── RotateArray.java │ ├── SetZeroes.java │ └── SpiralMatrix.java ├── easy │ ├── ArrayForm.java │ ├── BuildArray.java │ ├── Concatenation.java │ ├── DiagonalSum.java │ ├── EvenDigits.java │ ├── FlipImage.java │ ├── GoodPairs.java │ ├── GreatestCandies.java │ ├── HighestAltitude.java │ ├── LuckyNumbers.java │ ├── MatchingRule.java │ ├── MatrixRotation.java │ ├── MaxPopulation.java │ ├── OddCells.java │ ├── Pangram.java │ ├── RichestCustomer.java │ ├── RunningSum.java │ ├── ShuffleArray.java │ ├── SmallNumbers.java │ ├── SumZero.java │ ├── TargetArray.java │ ├── TransposeMatrix.java │ └── TwoSum.java └── hard │ └── MaxValue.java ├── 06-searching └── 06-searching.md ├── 07-sorting └── 07-sorting.md ├── 08-strings └── 08-strings.md ├── 09-patterns └── 09-patterns.md ├── 10-recursion └── 10-recursion.md ├── 11-bitwise └── 11-bitwise.md └── 12-math └── 12-math.md /.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | .idea/ 3 | problem-attic.iml -------------------------------------------------------------------------------- /01-flow-of-program/01-flow-of-program.md: -------------------------------------------------------------------------------- 1 | [Video Link](https://youtu.be/lhELGQAV4gg) 2 | 3 | ## Create flowchart and pseudocode for the following: 4 | 5 | 1. Input a year and find whether it is a leap year or not. 6 | 2. Take two numbers and print the sum of both. 7 | 3. Take a number as input and print the multiplication table for it. 8 | 4. Take a 2 numbers as inputs and find their HCF and LCM. 9 | 5. Keep taking numbers as inputs till the user enters ‘x’, after that print sum 10 | of all. -------------------------------------------------------------------------------- /02-first-java/02-first-java.md: -------------------------------------------------------------------------------- 1 | # [Video Link](https://youtu.be/TAtrPoaJ7gc) 2 | 3 | ## Write Java programs for the following: 4 | 5 | 1. Write a program to print whether a number is even or odd, also take 6 | input. 7 | 2. Take name as input and print a greeting message for that name. 8 | 3. Write a program to input principle, time, and rate (P, T, R) from the user and 9 | find Simple Interest. 10 | 4. Take in two numbers and an operator (+, -, *, /) and calculate the value. 11 | (Use if conditions) 12 | 5. Take 2 numbers as input and print the largest number. 13 | 6. Input currency in rupees and output in USD. 14 | 15 | -------------------------------------------------------------------------------- /02-first-java/Calculator.java: -------------------------------------------------------------------------------- 1 | //5. Take in two numbers and an operator (+, -, *, /) and calculate the value. (Use if conditions) 2 | import java.util.Scanner; 3 | public class Calculator { 4 | public static void main(String[] args) { 5 | Scanner in = new Scanner(System.in); 6 | System.out.print("Enter a number: "); 7 | float a = in.nextFloat(); 8 | System.out.print("Enter another number: "); 9 | float b = in.nextFloat(); 10 | System.out.print("Enter operation: "); 11 | char op = in.next().charAt(0); 12 | if (op == '+') { 13 | System.out.println(a + " + " + b + " = " + (a + b)); 14 | } else if (op == '-') { 15 | System.out.println(a + " - " + b + " = " + (a - b)); 16 | } else if (op == '*') { 17 | System.out.println(a + " * " + b + " = " + (a * b)); 18 | } else if (op == '/') { 19 | System.out.println(a + " / " + b + " = " + (a / b)); 20 | } else { 21 | System.out.println("Invalid operator"); 22 | } 23 | // switch (op){ 24 | // case '+': 25 | // System.out.println(a+" + "+b+" = "+(a+b)); 26 | // break; 27 | // case '-': 28 | // System.out.println(a+" - "+b+" = "+(a-b)); 29 | // break; 30 | // case '*': 31 | // System.out.println(a+" * "+b+" = "+(a*b)); 32 | // break; 33 | // case '/': 34 | // System.out.println(a+" / "+b+" = "+(a/b)); 35 | // break; 36 | // default: 37 | // System.out.println("Invalid operator"); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /02-first-java/ContinuousSum.java: -------------------------------------------------------------------------------- 1 | // 9. Take integer inputs till the user enters 0 and print the sum of all numbers (HINT: while loop) 2 | import java.util.Scanner; 3 | public class ContinuousSum { 4 | public static void main(String[] args) { 5 | Scanner in = new Scanner(System.in); 6 | int sum = 0, temp; 7 | do { 8 | System.out.print("Enter a number (Press 0 to quit): "); 9 | temp = in.nextInt(); 10 | sum += temp; 11 | }while(temp != 0); 12 | System.out.println("Total sum: "+sum); 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /02-first-java/CurrencyConverter.java: -------------------------------------------------------------------------------- 1 | // 8. Input currency in rupee and output in dollar. 2 | import java.util.Scanner; 3 | 4 | public class CurrencyConverter { 5 | public static void main(String[] args) { 6 | Scanner in = new Scanner(System.in); 7 | System.out.println("Enter money in rupees: Rs "); 8 | float money = in.nextfloat(); 9 | System.out.println("Money in US Dollars: $ " + (0.013*money)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /02-first-java/EvenOdd.java: -------------------------------------------------------------------------------- 1 | // 2. Write a program to print whether a number is even or odd, also take input. 2 | import java.util.Scanner; 3 | public class EvenOdd{ 4 | public static void main(String[] args) { 5 | Scanner in = new Scanner(System.in); 6 | System.out.print("Enter a number: "); 7 | int n = in.nextInt(); 8 | if (n % 2 == 0){ 9 | System.out.println("Even"); 10 | } 11 | else{ 12 | System.out.println("Odd"); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /02-first-java/Factorial.java: -------------------------------------------------------------------------------- 1 | // 1. Write a program to print factorial of a number, also take input. 2 | 3 | import java.util.Scanner; 4 | 5 | public class Factorial { 6 | public static void main(String[] args) { 7 | Scanner in = new Scanner(System.in); 8 | System.out.print("Enter a number: "); 9 | int n = in.nextInt(); 10 | System.out.println("Factorial of " + n + " is " + factorial(n)); 11 | } 12 | static int factorial(int n) 13 | { 14 | int ans = 1; 15 | for(int i = 2; i <= n; i++) 16 | { 17 | ans *= i; 18 | } 19 | return ans; 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /02-first-java/Factors.java: -------------------------------------------------------------------------------- 1 | //7. Input a number and print all the factors of that number (use loops). 2 | import java.util.Scanner; 3 | public class Factors { 4 | public static void main(String[] args) { 5 | Scanner in = new Scanner(System.in); 6 | System.out.print("Enter a number: "); 7 | int num = in.nextInt(); 8 | System.out.print("Factors of "+num+": "); 9 | for (int i = 1; i <= num; i++) 10 | { 11 | if (num % i == 0) 12 | { 13 | System.out.print(i+" "); 14 | } 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /02-first-java/Greeting.java: -------------------------------------------------------------------------------- 1 | // 3. Take name as input and print a greeting message for that name. 2 | import java.util.Scanner; 3 | 4 | public class Greeting { 5 | public static void main(String[] args) { 6 | Scanner in = new Scanner(System.in); 7 | System.out.print("Enter your name: "); 8 | String name = in.nextLine(); 9 | System.out.println("Hey " + name + "!"); 10 | } 11 | } -------------------------------------------------------------------------------- /02-first-java/LargestNumContinuous.java: -------------------------------------------------------------------------------- 1 | // 10. Take integer inputs till the user enters 0 and print the largest number from all. 2 | import java.util.Scanner; 3 | public class LargestNumContinuous { 4 | public static void main(String[] args) { 5 | Scanner in = new Scanner(System.in); 6 | int max = Integer.MIN_VALUE, temp = Integer.MIN_VALUE; 7 | do { 8 | if (max < temp) { 9 | max = temp; 10 | } 11 | System.out.print("Enter a number (Press 0 to quit): "); 12 | temp = in.nextInt(); 13 | }while(temp != 0); 14 | System.out.println("Largest of all: "+max); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /02-first-java/LargestNumber.java: -------------------------------------------------------------------------------- 1 | // 6. Take 2 numbers as input and print the largest number. 2 | import java.util.Scanner; 3 | 4 | public class LargestNumber { 5 | public static void main(String[] args) { 6 | Scanner in = new Scanner(System.in); 7 | System.out.println("Enter a number: "); 8 | float num1 = in.nextFloat(); 9 | System.out.println("Enter another number: "); 10 | float num2 = in.nextFloat(); 11 | if (num1 == num2) 12 | { 13 | System.out.println("Both are equal."); 14 | } 15 | else if(num1 > num2) 16 | { 17 | System.out.println(num1 + " is greater"); 18 | } 19 | else 20 | { 21 | System.out.println(num2 + " is greater"); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /02-first-java/SimpleInterest.java: -------------------------------------------------------------------------------- 1 | // 4. Write a program to input principle, time and rate (P, T, R) from user and find Simple Interest. 2 | import java.util.Scanner; 3 | public class SimpleInterest { 4 | public static void main(String[] args) { 5 | Scanner in = new Scanner(System.in); 6 | float P, T, R; 7 | System.out.println("Enter the following details"); 8 | System.out.println("Principle amount: "); 9 | P = in.nextFloat(); 10 | System.out.println("Time in years: "); 11 | T = in.nextFloat(); 12 | System.out.println("Rate of Interest: "); 13 | R = in.nextFloat(); 14 | System.out.println("Interest: " + (P*T*R) / 100); 15 | } 16 | } -------------------------------------------------------------------------------- /03-conditionals-loops/03-conditionals-loops.md: -------------------------------------------------------------------------------- 1 | # [Video Link](https://youtu.be/ldYLYRNaucM) 2 | ## Write Java programs for the following: 3 | 4 | ### Basic Java Programs 5 | 1. Area Of Circle Java Program 6 | 2. Area Of Triangle 7 | 3. Area Of Rectangle Program 8 | 4. Area Of Isosceles Triangle 9 | 5. Area Of Parallelogram 10 | 6. Area Of Rhombus 11 | 7. Area Of Equilateral Triangle 12 | 8. Perimeter Of Circle 13 | 9. Perimeter Of Equilateral Triangle 14 | 10. Perimeter Of Parallelogram 15 | 11. Perimeter Of Rectangle 16 | 12. Perimeter Of Square 17 | 13. Perimeter Of Rhombus 18 | 14. Volume Of Cone Java Program 19 | 15. Volume Of Prism 20 | 16. Volume Of Cylinder 21 | 17. Volume Of Sphere 22 | 18. Volume Of Pyramid 23 | 19. Curved Surface Area Of Cylinder 24 | 20. Total Surface Area Of Cube 25 | 21. Fibonacci Series In Java Programs 26 | 22. [Subtract the Product and Sum of Digits of an Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/) 27 | 23. Input a number and print all the factors of that number (use loops). 28 | 24. Take integer inputs till the user enters 0 and print the sum of all numbers 29 | (HINT: while loop) 30 | 25. Take integer inputs till the user enters 0 and print the largest number from 31 | all. 32 | 33 | ### Intermediate Java Programs 34 | 1. Factorial Program In Java 35 | 2. Calculate Electricity Bill 36 | 3. Calculate Average Of N Numbers 37 | 4. Calculate Discount Of Product 38 | 5. Calculate Distance Between Two Points 39 | 6. Calculate Commission Percentage 40 | 7. Power In Java 41 | 8. Calculate Depreciation of Value 42 | 9. Calculate Batting Average 43 | 10. Calculate CGPA Java Program 44 | 11. Compound Interest Java Program 45 | 12. Calculate Average Marks 46 | 13. Addition Of Two Numbers 47 | 14. Sum Of N Numbers 48 | 15. Armstrong Number In Java 49 | 16. Find Ncr & Npr 50 | 17. Reverse A String In Java 51 | 18. Find if a number is palindrome or not 52 | 19. Future Investment Value 53 | 20. HCF Of Two Numbers Program 54 | 21. LCM Of Two Numbers 55 | 22. Java Program Vowel Or Consonant 56 | 23. Perfect Number In Java 57 | 24. Check Leap Year Or Not 58 | 25. Sum Of A Digits Of Number 59 | 26. Kunal is allowed to go out with his friends only on the even days of a given month. Write a program to count the number of days he can go out in the month of August. 60 | 27. Write a program to print the sum of negative numbers, sum of positive even numbers and the sum of positive odd numbers from a list of numbers (N) entered by the user. The list terminates when the user enters a zero. 61 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/AreaOfCircle.java: -------------------------------------------------------------------------------- 1 | // 1. Area Of Circle Java Program 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class AreaOfCircle { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter radius of the circle: "); 10 | float r = in.nextFloat(); 11 | double area = Math.PI * r * r; 12 | System.out.println("Area of circle: "+area); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/AreaOfEquilateralTriangle.java: -------------------------------------------------------------------------------- 1 | // 7. Area Of Equilateral Triangle 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class AreaOfEquilateralTriangle { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter side of triangle: "); 10 | float a = in.nextFloat(); 11 | double area = (Math.sqrt(3) * a * a)/4; 12 | System.out.println("Area of equilateral triangle: "+area); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/AreaOfIsoscelesTriangle.java: -------------------------------------------------------------------------------- 1 | // 4. Area Of Isosceles Triangle 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class AreaOfIsoscelesTriangle { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter equal side of triangle: "); 10 | float b = in.nextFloat(); 11 | System.out.print("Enter final side of triangle: "); 12 | float a = in.nextFloat(); 13 | double area = a * Math.sqrt((b*b)-((a*a)/4)) / 2; 14 | System.out.println("Area of isosceles triangle: "+area); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/AreaOfParallelogram.java: -------------------------------------------------------------------------------- 1 | // 5. Area Of Parallelogram 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class AreaOfParallelogram { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter side 1 of parallelogram: "); 10 | float a = in.nextFloat(); 11 | System.out.print("Enter side 2 of parallelogram: "); 12 | float b = in.nextFloat(); 13 | System.out.print("Enter acute angle between the sides in degrees: "); 14 | double angle = Math.toRadians(in.nextFloat()); 15 | double area = a * b * Math.sin(angle); 16 | System.out.println("Area of Parallelogram: "+area); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/AreaOfRectangle.java: -------------------------------------------------------------------------------- 1 | // 3. Area Of Rectangle Program 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class AreaOfRectangle { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter length of rectangle: "); 10 | float l = in.nextFloat(); 11 | System.out.print("Enter breadth of rectangle: "); 12 | float b = in.nextFloat(); 13 | System.out.println("Area of Rectangle: "+(l*b)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/AreaOfRhombus.java: -------------------------------------------------------------------------------- 1 | // 6. Area Of Rhombus 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class AreaOfRhombus { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter side of rhombus: "); 10 | float a = in.nextFloat(); 11 | System.out.print("Enter diagonal of rhombus: "); 12 | float p = in.nextFloat(); 13 | double area = p * (Math.sqrt((4*a*a)-(p*p)))/2; 14 | System.out.println("Area of Rhombus: "+area); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/AreaOfTriangle.java: -------------------------------------------------------------------------------- 1 | // 2. Area Of Triangle 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class AreaOfTriangle { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter side a of triangle: "); 10 | float a = in.nextFloat(); 11 | System.out.print("Enter side b of triangle: "); 12 | float b = in.nextFloat(); 13 | System.out.print("Enter side c of triangle: "); 14 | float c = in.nextFloat(); 15 | double area, s = (a + b + c)/2; 16 | area = Math.sqrt(s*(s-a)*(s-b)*(s-c)); 17 | System.out.println("Area of triangle: " +area); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/CSAOfCylinder.java: -------------------------------------------------------------------------------- 1 | // 19. Curved Surface Area Of Cylinder 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class CSAOfCylinder { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter height of cylinder: "); 10 | float h = in.nextFloat(); 11 | System.out.print("Enter radius of cylinder: "); 12 | float r = in.nextFloat(); 13 | double csa = 2 * Math.PI * r * h; 14 | System.out.println("Curved Surface Area of cylinder: "+csa); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/DiffOfSDnPD.java: -------------------------------------------------------------------------------- 1 | //22. [Subtract the Product and Sum of Digits of an Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/) 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class DiffOfSDnPD { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter a number: "); 10 | int n = in.nextInt(); 11 | int sod = 0, pod = 1, temp; 12 | while (n > 0){ 13 | temp = n%10; 14 | sod += temp; 15 | pod *= temp; 16 | n /= 10; 17 | } 18 | System.out.println("Difference: "+(pod-sod)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/FibonacciSeries.java: -------------------------------------------------------------------------------- 1 | // 21. Fibonacci Series In Java Programs 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class FibonacciSeries { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter a number: "); 10 | int n = in.nextInt(); 11 | int a = 0, b = 1, temp; 12 | System.out.print("0 "); 13 | for (int i = 1; i < n ; i++) 14 | { 15 | temp = b; 16 | b += a; 17 | a = temp; 18 | System.out.print(b+" "); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/PerimeterOfCircle.java: -------------------------------------------------------------------------------- 1 | // 8. Perimeter Of Circle 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class PerimeterOfCircle { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter radius of the circle: "); 10 | float r = in.nextFloat(); 11 | double perimeter = 2 * Math.PI * r; 12 | System.out.println("Perimeter of circle: "+perimeter); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/PerimeterOfEquilateralTriangle.java: -------------------------------------------------------------------------------- 1 | // 9. Perimeter Of Equilateral Triangle 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class PerimeterOfEquilateralTriangle { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter side of triangle: "); 10 | double a = in.nextFloat(); 11 | double perimeter = 3 * a; 12 | System.out.println("Perimeter of equilateral triangle: "+perimeter); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/PerimeterOfParallelogram.java: -------------------------------------------------------------------------------- 1 | // 10. Perimeter Of Parallelogram 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class PerimeterOfParallelogram { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | float perimeter = 0; 10 | int count = 1; 11 | while (count != 5) 12 | { 13 | System.out.print("Enter side " +count+ " of parallelogram: "); 14 | perimeter += in.nextFloat(); 15 | count += 1; 16 | } 17 | System.out.println("Perimeter of Parallelogram: "+perimeter); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/PerimeterOfRectangle.java: -------------------------------------------------------------------------------- 1 | // 11. Perimeter Of Rectangle 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class PerimeterOfRectangle { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter length of rectangle: "); 10 | float l = in.nextFloat(); 11 | System.out.print("Enter breadth of rectangle: "); 12 | float b = in.nextFloat(); 13 | System.out.println("Perimeter of Rectangle: "+(2*(l+b))); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/PerimeterOfSquare.java: -------------------------------------------------------------------------------- 1 | // 12. Perimeter Of Square 2 | // 13. Perimeter Of Rhombus 3 | // Both have all sides equal 4 | package basic; 5 | 6 | import java.util.Scanner; 7 | 8 | public class PerimeterOfSquare { 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | System.out.print("Enter side: "); 12 | float side = in.nextFloat(); 13 | System.out.println("Perimeter: "+(4*side)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/TSAOfCube.java: -------------------------------------------------------------------------------- 1 | // 20. Total Surface Area Of Cube 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class TSAOfCube { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter side: "); 10 | float side = in.nextFloat(); 11 | System.out.println("Total Surface Area Of Cube: "+(6*side*side)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/VolumeOfCone.java: -------------------------------------------------------------------------------- 1 | // 14. Volume Of Cone Java Program 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class VolumeOfCone { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter height of cone: "); 10 | float h = in.nextFloat(); 11 | System.out.print("Enter radius of cone: "); 12 | float r = in.nextFloat(); 13 | double volume = (Math.PI * r * r * h) / 3; 14 | System.out.println("Volume of cone: "+volume); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/VolumeOfCylinder.java: -------------------------------------------------------------------------------- 1 | //16. Volume Of Cylinder 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class VolumeOfCylinder { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter height of cylinder: "); 10 | float h = in.nextFloat(); 11 | System.out.print("Enter radius of cylinder: "); 12 | float r = in.nextFloat(); 13 | double volume = Math.PI * r * r * h; 14 | System.out.println("Volume of cylinder: "+volume); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/VolumeOfPrism.java: -------------------------------------------------------------------------------- 1 | // 15. Volume Of Prism 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class VolumeOfPrism { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter length of prism: "); 10 | float l = in.nextFloat(); 11 | System.out.print("Enter breadth of prism: "); 12 | float b = in.nextFloat(); 13 | System.out.print("Enter height of prism: "); 14 | float h = in.nextFloat(); 15 | float volume = l*b*h; 16 | System.out.println("Volume of prism: "+volume); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/VolumeOfPyramid.java: -------------------------------------------------------------------------------- 1 | // 18. Volume Of Pyramid 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class VolumeOfPyramid { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter length of pyramid: "); 10 | float l = in.nextFloat(); 11 | System.out.print("Enter breadth of pyramid: "); 12 | float b = in.nextFloat(); 13 | System.out.print("Enter height of pyramid: "); 14 | float h = in.nextFloat(); 15 | float volume = (l*b*h)/3; 16 | System.out.println("Volume of pyramid: "+volume); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /03-conditionals-loops/basic/VolumeOfSphere.java: -------------------------------------------------------------------------------- 1 | // 17. Volume Of Sphere 2 | package basic; 3 | 4 | import java.util.Scanner; 5 | 6 | public class VolumeOfSphere { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter radius of the sphere: "); 10 | float r = in.nextFloat(); 11 | double volume = 4*Math.PI*Math.pow(r,3)/3; 12 | System.out.println("Volume of Sphere: "+volume); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /04-functions/04-functions.md: -------------------------------------------------------------------------------- 1 | # [Video Link](https://youtu.be/vvanI8NRlSI) 2 | 3 | 1. [Define two methods to print the maximum and the minimum number respectively among three numbers entered by the user.](https://www.java67.com/2019/05/how-to-find-largest-and-smallest-of-three-numbers-in-java.html) 4 | 5 | 2. [Define a program to find out whether a given number is even or odd.](https://www.geeksforgeeks.org/java-program-to-check-if-a-given-integer-is-odd-or-even/) 6 | 7 | 3. [A person is eligible to vote if his/her age is greater than or equal to 18. Define a method to find out if he/she is eligible to vote.](https://www.efaculty.in/java-programs/voting-age-program-in-java/) 8 | 9 | 4. [Write a program to print the sum of two numbers entered by user by defining your own method.](https://code4coding.com/addition-of-two-numbers-in-java-using-method/) 10 | 11 | 5. [Define a method that returns the product of two numbers entered by user.](https://code4coding.com/java-program-to-multiply-two-numbers-using-method/) 12 | 13 | 6. [Write a program to print the circumference and area of a circle of radius entered by user by defining your own method.](https://beginnersbook.com/2014/01/java-program-to-calculate-area-and-circumference-of-circle/) 14 | 15 | 7. [Define a method to find out if a number is prime or not.](https://www.geeksforgeeks.org/java-program-to-check-if-a-number-is-prime-or-not/) 16 | 17 | 8. [Write a program that will ask the user to enter his/her marks (out of 100). Define a method that will display grades according to the marks entered as below:](https://www.techcrashcourse.com/2017/02/java-program-to-calculate-grade-of-students.html)
18 |
 
19 | Marks        Grade 
20 | 91-100         AA 
21 | 81-90          AB 
22 | 71-80          BB 
23 | 61-70          BC 
24 | 51-60          CD 
25 | 41-50          DD 
26 | <=40          Fail 
27 | 
28 | 29 | 9. [Write a program to print the factorial of a number by defining a method named 'Factorial'.](https://www.javatpoint.com/factorial-program-in-java) 30 | Factorial of any number n is represented by n! and is equal to 1 * 2 * 3 * .... * (n-1) *n. E.g.-
31 |
32 | 4! = 1 * 2 * 3 * 4 = 24 
33 | 3! = 3 * 2 * 1 = 6 
34 | 2! = 2 * 1 = 2 
35 | Also, 
36 | 1! = 1 
37 | 0! = 1
38 | 
39 | 40 | 10. [Write a function to find if a number is a palindrome or not. Take number as parameter.](https://www.geeksforgeeks.org/check-if-a-number-is-palindrome/) 41 | 42 | 11. Convert the programs in [flow of program](01-flow-of-program.md), [first java](02-first-java.md), [conditionals & loops](03-conditionals-loops.md) assignments into functions. 43 | 44 | 12. [Write a function to check if a given triplet is a Pythagorean triplet or not.](https://www.geeksforgeeks.org/find-pythagorean-triplet-in-an-unsorted-array/) (A Pythagorean triplet is when the sum of the square of two numbers is equal to the square of the third number). 45 | 46 | 13. [Write a function that returns all prime numbers between two given numbers.](https://www.geeksforgeeks.org/program-to-find-prime-numbers-between-given-interval/) 47 | 48 | 14. [Write a function that returns the sum of first n natural numbers.](https://www.geeksforgeeks.org/program-find-sum-first-n-natural-numbers/) 49 | -------------------------------------------------------------------------------- /05-arrays/05-arrays.md: -------------------------------------------------------------------------------- 1 | # [Video Link](https://youtu.be/n60Dn0UsbEk) 2 | 3 | ## Submit the following on your Leetcode profile itself. 4 | 5 | ### Easy 6 | 1. [Build Array from Permutation](https://leetcode.com/problems/build-array-from-permutation/) 7 | 2. [Concatenation of Array](https://leetcode.com/problems/concatenation-of-array/) 8 | 3. [Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array/) 9 | 4. [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth/) 10 | 5. [Shuffle the Array](https://leetcode.com/problems/shuffle-the-array/) 11 | 6. [Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/) 12 | 7. [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs/) 13 | 8. [How Many Numbers Are Smaller Than the Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/) 14 | 9. [Create Target Array in the Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order/) 15 | 10. [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram/) 16 | 11. [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule/) 17 | 12. [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude/) 18 | 13. [Flipping an Image](https://leetcode.com/problems/flipping-an-image/) 19 | 14. [Cells with Odd Values in a Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/) 20 | 15. [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum/) 21 | 16. [Find Numbers with Even Number of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits/) 22 | 17. [Transpose Matrix](https://leetcode.com/problems/transpose-matrix/) 23 | 18. [Add to Array-Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer/) 24 | 19. [Maximum Population Year](https://leetcode.com/problems/maximum-population-year/) 25 | 20. [Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation/) 26 | 21. [Two Sum](https://leetcode.com/problems/two-sum/) 27 | 22. [Find N Unique Integers Sum up to Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/) 28 | 23. [Saddle Point In Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix/) 29 | 24. [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) 30 | 25. [Reshape the Matrix](https://leetcode.com/problems/reshape-the-matrix/) 31 | 32 | ### Medium 33 | 1. [Spiral Matrix](https://leetcode.com/problems/spiral-matrix/) 34 | 2. [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) 35 | 3. [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) 36 | 4. [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/) 37 | 5. [Jump Game](https://leetcode.com/problems/jump-game/) 38 | 6. [Rotate Array](https://leetcode.com/problems/rotate-array/) 39 | 40 | ### Hard 41 | 1. [Max Value of Equation](https://leetcode.com/problems/max-value-of-equation/) 42 | 2. [First Missing Positive](https://leetcode.com/problems/first-missing-positive/) 43 | 3. [Good Array](https://leetcode.com/problems/check-if-it-is-a-good-array/) 44 | -------------------------------------------------------------------------------- /05-arrays/Medium/FirstLast.java: -------------------------------------------------------------------------------- 1 | package Medium; 2 | //4. [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/) 3 | 4 | import java.util.Arrays; 5 | import java.util.Scanner; 6 | 7 | public class FirstLast { 8 | public static void main(String[] args) { 9 | Scanner in = new Scanner(System.in); 10 | System.out.print("Enter length of array: "); 11 | int len = in.nextInt(); 12 | System.out.print("Enter numbers: "); 13 | int[] nums = new int[len]; 14 | for (int i=0; i < len; i++){ 15 | nums[i] = in.nextInt(); 16 | } 17 | System.out.print("Enter element to be searched: "); 18 | int target = in.nextInt(); 19 | System.out.println("Input Array: "+ Arrays.toString(nums)); 20 | System.out.println("First last position: "+ Arrays.toString(searchRange(nums, target))); 21 | } 22 | public static int[] searchRange(int[] nums, int target) { 23 | int[] res = {-1, -1}; 24 | res[0] = search(nums, target, true); 25 | if (res[0] != -1){ 26 | res[1] = search(nums, target, false); 27 | } 28 | return res; 29 | } 30 | public static int search(int[] nums, int target, boolean isFirst){ 31 | int start = 0; 32 | int end = nums.length - 1; 33 | int mid, res = -1; 34 | while (start <= end){ 35 | mid = start + (end - start)/2; 36 | if (target < nums[mid]){ 37 | end = mid-1; 38 | } 39 | else if (target > nums[mid]){ 40 | start = mid + 1; 41 | } 42 | else{ 43 | res = mid; 44 | if (isFirst){ 45 | end = mid-1; 46 | }else{ 47 | start = mid+1; 48 | } 49 | } 50 | } 51 | return res; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /05-arrays/Medium/JumpGame.java: -------------------------------------------------------------------------------- 1 | package Medium; 2 | //5. [Jump Game](https://leetcode.com/problems/jump-game/) 3 | 4 | import java.util.Arrays; 5 | import java.util.Scanner; 6 | 7 | public class JumpGame { 8 | public static void main(String[] args) { 9 | Scanner in = new Scanner(System.in); 10 | System.out.print("Enter length of array: "); 11 | int len = in.nextInt(); 12 | System.out.print("Enter numbers: "); 13 | int[] nums = new int[len]; 14 | for (int i=0; i < len; i++){ 15 | nums[i] = in.nextInt(); 16 | } 17 | System.out.println("Input Array: "+ Arrays.toString(nums)); 18 | System.out.println("Can reach the end?: "+ canJump(nums)); 19 | } 20 | public static boolean canJump(int[] nums) { 21 | int maxMoves = nums[0]; 22 | for (int i=0; i<= maxMoves; i++) { 23 | if (maxMoves >= nums.length-1) return true; 24 | if (maxMoves < i+nums[i]){ 25 | maxMoves = i+nums[i]; 26 | } 27 | } 28 | return false; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /05-arrays/Medium/ProductArray.java: -------------------------------------------------------------------------------- 1 | package Medium; 2 | //3. [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) 3 | 4 | import java.util.Arrays; 5 | import java.util.Scanner; 6 | 7 | public class ProductArray { 8 | public static void main(String[] args) { 9 | Scanner in = new Scanner(System.in); 10 | System.out.print("Enter length of array: "); 11 | int len = in.nextInt(); 12 | System.out.print("Enter numbers: "); 13 | int[] nums = new int[len]; 14 | for (int i=0; i < len; i++){ 15 | nums[i] = in.nextInt(); 16 | } 17 | System.out.println("Input Array: "+ Arrays.toString(nums)); 18 | System.out.println("Product Array: "+ Arrays.toString(productExceptSelf(nums))); 19 | } 20 | public static int[] productExceptSelf(int[] nums) { 21 | int len = nums.length; 22 | int[] res = new int[len]; 23 | int left = 1, right = 1; 24 | for (int i = 0; i < len; i++){ 25 | res[i] = 1; 26 | } 27 | for (int i = 0; i < len; i++){ 28 | res[i] *= left; 29 | left *= nums[i]; 30 | res[len-i-1] *= right; 31 | right *= nums[len-i-1]; 32 | } 33 | return res; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /05-arrays/Medium/RotateArray.java: -------------------------------------------------------------------------------- 1 | package Medium; 2 | //6. [Rotate Array](https://leetcode.com/problems/rotate-array/) 3 | 4 | import java.util.Arrays; 5 | import java.util.Scanner; 6 | 7 | public class RotateArray { 8 | public static void main(String[] args) { 9 | Scanner in = new Scanner(System.in); 10 | System.out.print("Enter length of array: "); 11 | int len = in.nextInt(); 12 | System.out.print("Enter numbers: "); 13 | int[] nums = new int[len]; 14 | for (int i=0; i < len; i++){ 15 | nums[i] = in.nextInt(); 16 | } 17 | System.out.print("Enter number of rotations: "); 18 | int k = in.nextInt(); 19 | System.out.println("Input Array: "+ Arrays.toString(nums)); 20 | rotate(nums, k); 21 | } 22 | public static void rotate(int[] nums, int k) { 23 | int n = nums.length; 24 | k = k % n; 25 | rotateSubArray(nums, 0, n-k); 26 | rotateSubArray(nums, n-k, n); 27 | rotateSubArray(nums, 0 , n); 28 | System.out.println("Rotated Array: "+ Arrays.toString(nums)); 29 | } 30 | public static void rotateSubArray(int[] nums, int start, int end){ 31 | while(start < end){ 32 | swap(nums, start, end-1); 33 | start++; 34 | end--; 35 | } 36 | } 37 | public static void swap(int[] nums, int i, int j){ 38 | int temp = nums[i]; 39 | nums[i] = nums[j]; 40 | nums[j] = temp; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /05-arrays/Medium/SetZeroes.java: -------------------------------------------------------------------------------- 1 | //2. [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) 2 | package Medium; 3 | 4 | import java.util.Arrays; 5 | import java.util.Scanner; 6 | 7 | public class SetZeroes { 8 | public static void main(String[] args) { 9 | Scanner in = new Scanner(System.in); 10 | System.out.print("Enter num of rows: "); 11 | int rows = in.nextInt(); 12 | System.out.print("Enter num of cols: "); 13 | int cols = in.nextInt(); 14 | int[][] matrix = new int[rows][cols]; 15 | for (int i=0; i < rows; i++){ 16 | System.out.print("Enter elements in row "+(i+1)+": "); 17 | for (int j=0; j < cols; j++) { 18 | matrix[i][j] = in.nextInt(); 19 | } 20 | } 21 | setZeroes(matrix); 22 | } 23 | public static void setZeroes(int[][] matrix) { 24 | int[][] res = new int[matrix.length][matrix[0].length]; 25 | for (int i = 0; i < matrix.length; i++){ 26 | for (int j = 0; j < matrix[0].length; j++){ 27 | res[i][j] = matrix[i][j]; 28 | } 29 | } 30 | for (int i = 0; i < matrix.length; i++){ 31 | for (int j = 0; j < matrix[0].length; j++){ 32 | if (res[i][j] == 0){ 33 | setRowZero(matrix, i); 34 | setColumnZero(matrix, j); 35 | } 36 | } 37 | } 38 | for (int[] row: matrix){ 39 | System.out.println(Arrays.toString(row)); 40 | } 41 | } 42 | public static void setRowZero(int[][] matrix, int row){ 43 | for (int i = row, j = 0; j < matrix[0].length; j++){ 44 | matrix[i][j] = 0; 45 | } 46 | } 47 | public static void setColumnZero(int[][] matrix, int column){ 48 | for (int i = 0, j = column; i < matrix.length; i++){ 49 | matrix[i][j] = 0; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /05-arrays/Medium/SpiralMatrix.java: -------------------------------------------------------------------------------- 1 | package Medium; 2 | //1. [Spiral Matrix](https://leetcode.com/problems/spiral-matrix/) 3 | 4 | import java.util.ArrayList; 5 | import java.util.Scanner; 6 | import java.util.List; 7 | 8 | public class SpiralMatrix { 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | System.out.print("Enter num of rows: "); 12 | int rows = in.nextInt(); 13 | System.out.print("Enter num of cols: "); 14 | int cols = in.nextInt(); 15 | int[][] matrix = new int[rows][cols]; 16 | for (int i=0; i < rows; i++){ 17 | System.out.print("Enter elements in row "+(i+1)+": "); 18 | for (int j=0; j < cols; j++) { 19 | matrix[i][j] = in.nextInt(); 20 | } 21 | } 22 | System.out.println("Max wealth: "+ spiralOrder(matrix)); 23 | } 24 | public static List spiralOrder(int[][] matrix) { 25 | List res = new ArrayList<>(); 26 | int minR = 0, minC = 0, maxR = matrix.length-1, maxC = matrix[0].length-1, count = (maxR+1)*(maxC+1); 27 | while (count > 0){ 28 | for (int i = minR, j = minC; j <= maxC && count > 0; j++){ 29 | res.add(matrix[i][j]); 30 | count --; 31 | } 32 | minR++; 33 | for (int i = minR, j = maxC; i <= maxR && count > 0; i++){ 34 | res.add(matrix[i][j]); 35 | count --; 36 | } 37 | maxC--; 38 | for (int i = maxR, j = maxC; j >= minC && count > 0; j--){ 39 | res.add(matrix[i][j]); 40 | count --; 41 | } 42 | maxR--; 43 | for (int i = maxR, j = minC; i >= minR && count > 0; i--){ 44 | res.add(matrix[i][j]); 45 | count --; 46 | } 47 | minC++; 48 | } 49 | return res; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /05-arrays/easy/ArrayForm.java: -------------------------------------------------------------------------------- 1 | package easy; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.Scanner; 7 | 8 | //18. [Add to Array-Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer/) 9 | public class ArrayForm { 10 | public static void main(String[] args) { 11 | Scanner in = new Scanner(System.in); 12 | System.out.print("Enter length of array: "); 13 | int len = in.nextInt(); 14 | System.out.print("Enter numbers: "); 15 | int[] digits = new int[len]; 16 | for (int i=0; i < len; i++){ 17 | digits[i] = in.nextInt(); 18 | } 19 | System.out.print("Enter number to be added: "); 20 | int num = in.nextInt(); 21 | System.out.println("Input Array: "+ Arrays.toString(digits)); 22 | System.out.println("Built Array: "+ addToArrayForm(digits, num)); 23 | } 24 | public static List addToArrayForm(int[] num, int k) { 25 | List res = new ArrayList<>(); 26 | for (int i = num.length-1; i >= 0; i--){ 27 | k += num[i]; 28 | res.add(0, k%10); 29 | k /= 10; 30 | } 31 | while (k > 0){ 32 | res.add(0,k%10); 33 | k /= 10; 34 | } 35 | 36 | return res; 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /05-arrays/easy/BuildArray.java: -------------------------------------------------------------------------------- 1 | package easy;// 1. [Build Array from Permutation](https://leetcode.com/problems/build-array-from-permutation/) 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class BuildArray { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter length of array: "); 10 | int len = in.nextInt(); 11 | System.out.print("Enter numbers: "); 12 | int[] nums = new int[len]; 13 | for (int i=0; i < len; i++){ 14 | nums[i] = in.nextInt(); 15 | } 16 | System.out.println("Input Array: "+Arrays.toString(nums)); 17 | System.out.println("Built Array: "+ Arrays.toString(buildArray(nums))); 18 | } 19 | public static int[] buildArray(int[] nums) { 20 | int n = nums.length; 21 | int[] res = new int[n]; 22 | for (int i = 0; i < n; i++){ 23 | res[i] = nums[nums[i]]; 24 | } 25 | return res; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /05-arrays/easy/Concatenation.java: -------------------------------------------------------------------------------- 1 | package easy;// 2. [easy.Concatenation of Array](https://leetcode.com/problems/concatenation-of-array/) 2 | import java.util.Arrays; 3 | import java.util.Scanner; 4 | 5 | public class Concatenation { 6 | public static void main(String[] args) { 7 | Scanner in = new Scanner(System.in); 8 | System.out.print("Enter length of array: "); 9 | int len = in.nextInt(); 10 | System.out.print("Enter numbers: "); 11 | int[] nums = new int[len]; 12 | for (int i=0; i < len; i++){ 13 | nums[i] = in.nextInt(); 14 | } 15 | System.out.println("Input Array: "+ Arrays.toString(nums)); 16 | System.out.println("Built Array: "+ Arrays.toString(getConcatenation(nums))); 17 | } 18 | public static int[] getConcatenation(int[] nums) { 19 | int n = 2 * nums.length; 20 | int[] res = new int[n]; 21 | for (int i = 0; i < n; i++){ 22 | res[i] = nums[i%(n/2)]; 23 | } 24 | return res; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /05-arrays/easy/DiagonalSum.java: -------------------------------------------------------------------------------- 1 | package easy;// 15. [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum/) 2 | 3 | import java.util.Scanner; 4 | 5 | public class DiagonalSum { 6 | public static void main(String[] args) { 7 | Scanner in = new Scanner(System.in); 8 | System.out.print("Enter num of rows: "); 9 | int rows = in.nextInt(); 10 | System.out.print("Enter num of cols: "); 11 | int cols = in.nextInt(); 12 | int[][] matrix = new int[rows][cols]; 13 | for (int i=0; i < rows; i++){ 14 | System.out.print("Enter elements in row "+(i+1)+": "); 15 | for (int j=0; j < cols; j++) { 16 | matrix[i][j] = in.nextInt(); 17 | } 18 | } 19 | System.out.println("Sum along diagonals: "+ diagonalSum(matrix)); 20 | } 21 | public static int diagonalSum(int[][] mat) { 22 | int len = mat.length, sum = 0; 23 | for(int i = 0; i < len; i++){ 24 | int j = len-i-1; 25 | if(i != j) 26 | { 27 | sum += mat[i][j]; 28 | } 29 | sum += mat[i][i]; 30 | } 31 | return sum; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /05-arrays/easy/EvenDigits.java: -------------------------------------------------------------------------------- 1 | package easy; 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | // 16. [Find Numbers with Even Number of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits/) 7 | public class EvenDigits { 8 | public static void main(String[] args) { 9 | Scanner in = new Scanner(System.in); 10 | System.out.print("Enter length of array: "); 11 | int len = in.nextInt(); 12 | System.out.print("Enter numbers: "); 13 | int[] nums = new int[len]; 14 | for (int i=0; i < len; i++){ 15 | nums[i] = in.nextInt(); 16 | } 17 | System.out.println("Input Array: "+ Arrays.toString(nums)); 18 | System.out.println("Numbers having even digits count: "+ findNumbers(nums)); 19 | } 20 | public static int findNumbers(int[] nums) { 21 | int res = 0; 22 | for (int i = 0; i < nums.length; i++){ 23 | if(isEven(nums[i])){ 24 | res += 1; 25 | } 26 | } 27 | return res; 28 | } 29 | public static boolean isEven(int n){ 30 | int total_digits = 0; 31 | while(n > 0){ 32 | total_digits += 1; 33 | n = n/10; 34 | } 35 | return total_digits % 2 == 0; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /05-arrays/easy/FlipImage.java: -------------------------------------------------------------------------------- 1 | package easy;// 13. [Flipping an Image](https://leetcode.com/problems/flipping-an-image/) 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class FlipImage { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter num of rows: "); 10 | int rows = in.nextInt(); 11 | System.out.print("Enter num of cols: "); 12 | int cols = in.nextInt(); 13 | int[][] image = new int[rows][cols]; 14 | for (int i=0; i < rows; i++){ 15 | System.out.print("Enter elements in row "+(i+1)+": "); 16 | for (int j=0; j < cols; j++) { 17 | image[i][j] = in.nextInt(); 18 | } 19 | } 20 | System.out.println("Original Image: "); 21 | for (int[] row:image){ 22 | System.out.println(Arrays.toString(row)); 23 | } 24 | System.out.println("Flipped Image: "); 25 | image = flipAndInvertImage(image); 26 | for (int[] row:image){ 27 | System.out.println(Arrays.toString(row)); 28 | } 29 | } 30 | public static int[][] flipAndInvertImage(int[][] image) { 31 | int rows = image.length; 32 | for (int i = 0; i < rows; i++){ 33 | int start = 0; 34 | int end = image[i].length-1; 35 | 36 | while(start <= end) { 37 | int temp = invert(image[i][start]); 38 | image[i][start] = invert(image[i][end]); 39 | image[i][end] = temp; 40 | 41 | start++; 42 | end--; 43 | } 44 | } 45 | return image; 46 | } 47 | public static int invert(int n){ 48 | if (n == 0) 49 | return 1; 50 | else 51 | return 0; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /05-arrays/easy/GoodPairs.java: -------------------------------------------------------------------------------- 1 | package easy;//7. [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs/) 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class GoodPairs { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter length of array: "); 10 | int len = in.nextInt(); 11 | System.out.print("Enter numbers: "); 12 | int[] nums = new int[len]; 13 | for (int i=0; i < len; i++){ 14 | nums[i] = in.nextInt(); 15 | } 16 | System.out.println("Input Array: "+ Arrays.toString(nums)); 17 | System.out.println("Good Identical Pairs: "+ numIdenticalPairs(nums)); 18 | } 19 | public static int numIdenticalPairs(int[] nums) { 20 | int n = nums.length; 21 | int count = 0; 22 | for (int i = 0; i < n-1; i++){ 23 | for (int j = i+1; j < n; j++){ 24 | if (nums[i] == nums[j]){ 25 | count += 1; 26 | } 27 | } 28 | } 29 | return count; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /05-arrays/easy/GreatestCandies.java: -------------------------------------------------------------------------------- 1 | package easy;// 6. [Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/) 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.Scanner; 7 | 8 | public class GreatestCandies { 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | System.out.print("Enter length of array: "); 12 | int len = in.nextInt(); 13 | System.out.print("Enter numbers: "); 14 | int[] nums = new int[len]; 15 | for (int i=0; i < len; i++){ 16 | nums[i] = in.nextInt(); 17 | } 18 | System.out.print("Enter number of extra candies: "); 19 | int ec = in.nextInt(); 20 | System.out.println("Input Array: "+ Arrays.toString(nums)); 21 | System.out.println("Can become greatest with extra candies: "+ kidsWithCandies(nums,ec)); 22 | } 23 | public static List kidsWithCandies(int[] candies, int extraCandies) { 24 | int len = candies.length, max = Integer.MIN_VALUE; 25 | ArrayList list = new ArrayList<>(); 26 | for (int i = 0; i < len; i++){ 27 | if(candies[i] > max){ 28 | max = candies[i]; 29 | } 30 | candies[i] += extraCandies; 31 | } 32 | for (int i = 0; i < len; i++) { 33 | if (candies[i] >= max){ 34 | list.add(true); 35 | } 36 | else{ 37 | list.add(false); 38 | } 39 | } 40 | return list; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /05-arrays/easy/HighestAltitude.java: -------------------------------------------------------------------------------- 1 | package easy; 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | // 12. [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude/) 7 | public class HighestAltitude { 8 | public static void main(String[] args) { 9 | Scanner in = new Scanner(System.in); 10 | System.out.print("Enter length of array: "); 11 | int len = in.nextInt(); 12 | System.out.print("Enter numbers: "); 13 | int[] nums = new int[len]; 14 | for (int i=0; i < len; i++){ 15 | nums[i] = in.nextInt(); 16 | } 17 | System.out.println("Input Array: "+Arrays.toString(nums)); 18 | System.out.println("Highest Altitude: "+ largestAltitude(nums)); 19 | } 20 | public static int largestAltitude(int[] gain) { 21 | int len = gain.length; 22 | int max = 0, sum = 0; 23 | for (int i=0; i max){ 26 | max = sum; 27 | } 28 | } 29 | return max; 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /05-arrays/easy/LuckyNumbers.java: -------------------------------------------------------------------------------- 1 | package easy;// 23. [Saddle Point In Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix/) 2 | import java.util.ArrayList; 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Scanner; 6 | 7 | public class LuckyNumbers { 8 | public static void main(String[] args) { 9 | Scanner in = new Scanner(System.in); 10 | System.out.print("Enter num of rows: "); 11 | int rows = in.nextInt(); 12 | System.out.print("Enter num of cols: "); 13 | int cols = in.nextInt(); 14 | int[][] numbers = new int[rows][cols]; 15 | for (int i=0; i < rows; i++){ 16 | System.out.print("Enter elements in row "+(i+1)+": "); 17 | for (int j=0; j < cols; j++) { 18 | numbers[i][j] = in.nextInt(); 19 | } 20 | } 21 | System.out.println("Lucky Number(s): "+ luckyNumbers(numbers)); 22 | } 23 | public static List luckyNumbers (int[][] matrix) { 24 | List res = new ArrayList<>(); 25 | int[] maxInColumns = new int[matrix[0].length]; 26 | int max; 27 | for (int i = 0; i < matrix[0].length; i++){ 28 | max = matrix[0][i]; 29 | for(int j = 0; j < matrix.length; j++){ 30 | if(max < matrix[j][i]){ 31 | max = matrix[j][i]; 32 | } 33 | } 34 | maxInColumns[i] = max; 35 | } 36 | int min, index; 37 | for(int i = 0; i < matrix.length; i++){ 38 | min = matrix[i][0]; 39 | index = 0; 40 | for (int j = 0; j < matrix[0].length; j++){ 41 | if (min > matrix[i][j]){ 42 | index = j; 43 | min = matrix[i][j]; 44 | } 45 | } 46 | if (min == maxInColumns[index]){ 47 | res.add(min); 48 | } 49 | } 50 | return res; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /05-arrays/easy/MatchingRule.java: -------------------------------------------------------------------------------- 1 | package easy; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | import java.util.Scanner; 6 | 7 | // 11. [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule/) 8 | public class MatchingRule { 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | System.out.print("Enter number of items: "); 12 | int rows = in.nextInt(); 13 | List> list = new ArrayList<>(); 14 | for (int i=0; i < rows; i++){ 15 | System.out.print("Enter elements in row "+(i+1)+": "); 16 | List temp = new ArrayList(); 17 | for (int j=0; j < 3; j++) { 18 | temp.add(in.next()); 19 | } 20 | list.add(temp); 21 | } 22 | System.out.print("Enter rule key: "); 23 | String ruleKey = in.next(); 24 | System.out.print("Enter rule value: "); 25 | String ruleValue = in.next(); 26 | System.out.println("Number of items matching given rule: "+ countMatches(list, ruleKey, ruleValue)); 27 | } 28 | public static int countMatches(List> items, String ruleKey, String ruleValue) { 29 | int checker; 30 | if (ruleKey.equals("type")){ 31 | checker = 0; 32 | } 33 | else if(ruleKey.equals("color")){ 34 | checker = 1; 35 | } 36 | else{ 37 | checker = 2; 38 | } 39 | int count = 0; 40 | for(int i=0;i max){ 30 | max = peopleInRange[j]; 31 | year = j+1950; 32 | } 33 | } 34 | return year; 35 | } 36 | public static void includeAlive(int[] arr, int start, int end){ 37 | for (int i = start; i < end; i++){ 38 | arr[i]++; 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /05-arrays/easy/OddCells.java: -------------------------------------------------------------------------------- 1 | package easy; 2 | 3 | import java.util.Scanner; 4 | 5 | // 14. [Cells with Odd Values in a Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/) 6 | public class OddCells { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter num of rows: "); 10 | int rows = in.nextInt(); 11 | System.out.print("Enter num of cols: "); 12 | int cols = in.nextInt(); 13 | int[][] accounts = new int[rows][cols]; 14 | System.out.print("Enter num of indices: "); 15 | int indices_rows = in.nextInt(); 16 | int[][] indices = new int[indices_rows][2]; 17 | for (int i=0; i < indices_rows; i++){ 18 | System.out.print("Enter elements in "+(i+1)+" row: "); 19 | for (int j=0; j < 2; j++) { 20 | indices[i][j] = in.nextInt(); 21 | } 22 | } 23 | System.out.println("Total number of odd cells: "+ oddCells(rows, cols, indices)); 24 | } 25 | public static int oddCells(int m, int n, int[][] indices) { 26 | int[][] res = new int[m][n]; 27 | int index; 28 | for (int i = 0; i < indices.length; i++){ 29 | index = indices[i][0]; 30 | for (int j = 0; j < n; j++){ 31 | res[index][j]++; 32 | } 33 | index = indices[i][1]; 34 | for (int k= 0; k < m; k++){ 35 | res[k][index]++; 36 | } 37 | } 38 | int count = 0; 39 | for (int i = 0;i < m;i++){ 40 | for (int j = 0;j < n;j++){ 41 | if(res[i][j] % 2 == 1) 42 | count++; 43 | } 44 | } 45 | return count; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /05-arrays/easy/Pangram.java: -------------------------------------------------------------------------------- 1 | package easy;// 10. [Check if the Sentence Is easy.Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram/) 2 | import java.util.Scanner; 3 | 4 | public class Pangram { 5 | public static void main(String[] args) { 6 | Scanner in = new Scanner(System.in); 7 | System.out.print("Enter the string: "); 8 | String sentence = in.next(); 9 | System.out.println("Is pangram? "+checkIfPangram(sentence)); 10 | } 11 | public static boolean checkIfPangram(String sentence) { 12 | int len = sentence.length(); 13 | if (len < 26){ 14 | return false; 15 | } 16 | int[] alphabets = new int[26]; 17 | int count = 0; 18 | for (int i = 0; i < len; i++){ 19 | int temp = sentence.charAt(i) - 97; 20 | if(alphabets[temp] != 1){ 21 | count += 1; 22 | alphabets[temp] = 1; 23 | } 24 | if(count == 26){ 25 | return true; 26 | } 27 | } 28 | return count == 26; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /05-arrays/easy/RichestCustomer.java: -------------------------------------------------------------------------------- 1 | package easy;//4. [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth/) 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class RichestCustomer { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter num of rows: "); 10 | int rows = in.nextInt(); 11 | System.out.print("Enter num of cols: "); 12 | int cols = in.nextInt(); 13 | int[][] accounts = new int[rows][cols]; 14 | for (int i=0; i < rows; i++){ 15 | System.out.print("Enter elements in row "+(i+1)+": "); 16 | for (int j=0; j < cols; j++) { 17 | accounts[i][j] = in.nextInt(); 18 | } 19 | } 20 | System.out.println("Max wealth: "+ maximumWealth(accounts)); 21 | } 22 | public static int maximumWealth(int[][] accounts) { 23 | int max = 0, sum; 24 | int rows = accounts.length; 25 | for (int i = 0; i < rows; i++){ 26 | sum = 0; 27 | for (int j = 0; j < accounts[i].length; j++){ 28 | sum += accounts[i][j]; 29 | } 30 | if (max < sum){ 31 | max = sum; 32 | } 33 | } 34 | return max; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /05-arrays/easy/RunningSum.java: -------------------------------------------------------------------------------- 1 | package easy;//3. [Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array/) 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class RunningSum { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter length of array: "); 10 | int len = in.nextInt(); 11 | System.out.print("Enter numbers: "); 12 | int[] nums = new int[len]; 13 | for (int i=0; i < len; i++){ 14 | nums[i] = in.nextInt(); 15 | } 16 | System.out.println("Input Array: "+ Arrays.toString(nums)); 17 | System.out.println("Built Array: "+ Arrays.toString(runningSum(nums))); 18 | } 19 | public static int[] runningSum(int[] nums) { 20 | int n = nums.length; 21 | for (int i = 1; i < n; i++){ 22 | nums[i] += nums[i-1]; 23 | } 24 | return nums; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /05-arrays/easy/ShuffleArray.java: -------------------------------------------------------------------------------- 1 | package easy;// 5. [Shuffle the Array](https://leetcode.com/problems/shuffle-the-array/) 2 | import java.util.Arrays; 3 | import java.util.Scanner; 4 | 5 | public class ShuffleArray { 6 | public static void main(String[] args) { 7 | Scanner in = new Scanner(System.in); 8 | System.out.print("Enter length of array: "); 9 | int len = in.nextInt(); 10 | System.out.print("Enter numbers: "); 11 | int[] nums = new int[len]; 12 | for (int i=0; i < len; i++){ 13 | nums[i] = in.nextInt(); 14 | } 15 | System.out.println("Input Array: "+ Arrays.toString(nums)); 16 | System.out.println("Shuffled Array: "+ Arrays.toString(shuffle(nums, len/2))); 17 | } 18 | public static int[] shuffle(int[] nums, int n) { 19 | int[] res = new int[2*n]; 20 | int count = 0, i = 0; 21 | while(count != n){ 22 | res[i] = nums[count]; 23 | res[i+1] = nums[count+n]; 24 | count += 1; 25 | i += 2; 26 | } 27 | return res; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /05-arrays/easy/SmallNumbers.java: -------------------------------------------------------------------------------- 1 | package easy;//8. [How Many Numbers Are Smaller Than the Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/) 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class SmallNumbers { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter length of array: "); 10 | int len = in.nextInt(); 11 | System.out.print("Enter numbers: "); 12 | int[] nums = new int[len]; 13 | for (int i=0; i < len; i++){ 14 | nums[i] = in.nextInt(); 15 | } 16 | System.out.println("Input Array: "+ Arrays.toString(nums)); 17 | System.out.println("Good Identical Pairs: "+ Arrays.toString(smallerNumbersThanCurrent(nums))); 18 | } 19 | public static int[] smallerNumbersThanCurrent(int[] nums) { 20 | int n = nums.length; 21 | int[] res = new int[n]; 22 | int count; 23 | for (int i = 0; i < n; i++){ 24 | count = 0; 25 | for (int j = 0; j < n; j++){ 26 | if (nums[i] > nums[j]){ 27 | count += 1; 28 | } 29 | } 30 | res[i] = count; 31 | } 32 | return res; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /05-arrays/easy/SumZero.java: -------------------------------------------------------------------------------- 1 | package easy; 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | // 22. [Find N Unique Integers Sum up to Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/) 7 | public class SumZero { 8 | public static void main(String[] args) { 9 | Scanner in = new Scanner(System.in); 10 | System.out.print("Enter a number: "); 11 | int n = in.nextInt(); 12 | System.out.println("Zero sum array: "+ Arrays.toString(sumZero(n))); 13 | } 14 | public static int[] sumZero(int n) { 15 | int res[] = new int[n]; 16 | for(int i = 0; i < n/2; i++){ 17 | res[i] = i+1; 18 | res[n-i-1] = -1 * (i+1); 19 | res[n/2] = 0; 20 | } 21 | if (n % 2 == 0){ 22 | res[n/2] = -1*n/2; 23 | } 24 | 25 | return res; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /05-arrays/easy/TargetArray.java: -------------------------------------------------------------------------------- 1 | package easy;// 9. [Create Target Array in the Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order/) 2 | import java.util.ArrayList; 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class TargetArray { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | System.out.print("Enter length of array: "); 10 | int len = in.nextInt(); 11 | System.out.print("Enter numbers in nums array: "); 12 | int[] nums = new int[len]; 13 | for (int i=0; i < len; i++){ 14 | nums[i] = in.nextInt(); 15 | } 16 | System.out.print("Enter numbers in index array: "); 17 | int[] index = new int[len]; 18 | for (int i=0; i < len; i++){ 19 | index[i] = in.nextInt(); 20 | } 21 | System.out.println("Input Array: "+ Arrays.toString(nums)); 22 | System.out.println("Built Array: "+ Arrays.toString(createTargetArray(nums, index))); 23 | } 24 | public static int[] createTargetArray(int[] nums, int[] index) { 25 | int n = nums.length; 26 | int[] target = new int[n]; 27 | ArrayList list = new ArrayList<>(); 28 | for (int i = 0; i < n; i++){ 29 | list.add(index[i],nums[i]); 30 | } 31 | for (int i = 0; i < n; i++){ 32 | target[i] = list.get(i); 33 | } 34 | return target; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /05-arrays/easy/TransposeMatrix.java: -------------------------------------------------------------------------------- 1 | package easy; 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | //17. [Transpose Matrix](https://leetcode.com/problems/transpose-matrix/) 7 | 8 | public class TransposeMatrix { 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | System.out.print("Enter num of rows: "); 12 | int rows = in.nextInt(); 13 | System.out.print("Enter num of cols: "); 14 | int cols = in.nextInt(); 15 | int[][] matrix = new int[rows][cols]; 16 | for (int i=0; i < rows; i++){ 17 | System.out.print("Enter elements in row "+(i+1)+": "); 18 | for (int j=0; j < cols; j++) { 19 | matrix[i][j] = in.nextInt(); 20 | } 21 | } 22 | System.out.println("Original matrix: "); 23 | for (int[] row:matrix){ 24 | System.out.println(Arrays.toString(row)); 25 | } 26 | System.out.println("Transposed matrix: "); 27 | int[][] t_matrix = transpose(matrix); 28 | for (int[] row:t_matrix){ 29 | System.out.println(Arrays.toString(row)); 30 | } 31 | } 32 | public static int[][] transpose(int[][] matrix) { 33 | int[][] res = new int[matrix[0].length][matrix.length]; 34 | for (int i = 0; i < matrix[0].length; i++) { 35 | for (int j = 0; j < matrix.length; j++) { 36 | res[i][j] = matrix[j][i]; 37 | } 38 | } 39 | return res; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /05-arrays/easy/TwoSum.java: -------------------------------------------------------------------------------- 1 | package easy; 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | //21. [Two Sum](https://leetcode.com/problems/two-sum/) 7 | public class TwoSum { 8 | public static void main(String[] args) { 9 | Scanner in = new Scanner(System.in); 10 | System.out.print("Enter length of array: "); 11 | int len = in.nextInt(); 12 | System.out.print("Enter numbers: "); 13 | int[] nums = new int[len]; 14 | for (int i=0; i < len; i++){ 15 | nums[i] = in.nextInt(); 16 | } 17 | System.out.print("Enter target number: "); 18 | int target = in.nextInt(); 19 | System.out.println("Input Array: "+ Arrays.toString(nums)); 20 | System.out.println("Indices: "+ Arrays.toString(twoSum(nums, target))); 21 | } 22 | public static int[] twoSum(int[] nums, int target) { 23 | int len = nums.length; 24 | for (int i = 0; i < len; i++){ 25 | for (int j = i + 1; j < len; j++) 26 | { 27 | if (nums[i] + nums[j] == target){ 28 | return new int[]{i, j}; 29 | } 30 | } 31 | } 32 | return new int[]{-1,-1}; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /05-arrays/hard/MaxValue.java: -------------------------------------------------------------------------------- 1 | package hard; 2 | 3 | import java.util.Scanner; 4 | 5 | public class MaxValue { 6 | public static void main(String[] args) { 7 | Scanner in = new Scanner(System.in); 8 | System.out.print("Enter num of rows: "); 9 | int rows = in.nextInt(); 10 | System.out.print("Enter num of cols: "); 11 | int cols = in.nextInt(); 12 | int[][] ordinates = new int[rows][cols]; 13 | for (int i=0; i < rows; i++){ 14 | System.out.print("Enter elements in row "+(i+1)+": "); 15 | for (int j=0; j < cols; j++) { 16 | ordinates[i][j] = in.nextInt(); 17 | } 18 | } 19 | System.out.print("Enter constraint k: "); 20 | int k = in.nextInt(); 21 | System.out.println("Max value of equation: "+ findMaxValueOfEquation(ordinates, k)); 22 | } 23 | public static int findMaxValueOfEquation(int[][] points, int k) { 24 | int max = Integer.MIN_VALUE, temp; 25 | for(int i = 0; i < points.length-1; i++){ 26 | for(int j = i+1; j < points.length; j++){ 27 | if (Math.abs(points[i][0] - points[j][0]) > k) break; 28 | temp = Math.abs(points[i][0] - points[j][0]) + points[i][1] + points[j][1]; 29 | if (temp > max) max = temp; 30 | } 31 | } 32 | return max; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /06-searching/06-searching.md: -------------------------------------------------------------------------------- 1 | # Videos: 2 | - [Linear Search](https://youtu.be/_HRA37X8N_Q) 3 | - [Binary Search](https://youtu.be/f6UU7V3szVw) 4 | - [Binary Search Questions](https://youtu.be/W9QJ8HaRvJQ) 5 | - [Binary Search in 2D Arrays](https://youtu.be/enI_KyGLYPo) 6 | 7 | # Problems: 8 | 9 | ## Easy 10 | - [Square Root](https://leetcode.com/problems/sqrtx/) 11 | - [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower/) 12 | - [First Bad Version](https://leetcode.com/problems/first-bad-version/) 13 | - [Two Sum II - Input array is sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) 14 | - [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square/) 15 | - [Arranging Coins(Easy)](https://leetcode.com/problems/arranging-coins/) 16 | - [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target/) 17 | - [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number/) 18 | - [Search Insert Position](https://leetcode.com/problems/search-insert-position/) 19 | - [Peak Index in a Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array/) 20 | - [Count Negative Numbers in a Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/) 21 | - [Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays/) 22 | - [Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/) 23 | - [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap/) 24 | - [Check If N and Its Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist/) 25 | - [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x/) 26 | - [Binary Search](https://leetcode.com/problems/binary-search/) 27 | 28 | ## Medium 29 | - [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/) 30 | - [Single Element in a Sorted Array](https://leetcode.com/problems/single-element-in-a-sorted-array/) 31 | - [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/) 32 | - [Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii/) 33 | - [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) 34 | - [Find Peak Element](https://leetcode.com/problems/find-peak-element/) 35 | - [Find Right Interval](https://leetcode.com/problems/find-right-interval/) 36 | - [Reach a Number](https://leetcode.com/problems/reach-a-number/) 37 | - [Maximum Value at a Given Index in a Bounded Array](https://leetcode.com/problems/maximum-value-at-a-given-index-in-a-bounded-array/) 38 | - [Koko Eating Bananas](https://leetcode.com/problems/koko-eating-bananas/) 39 | - [Minimum Absolute Sum Difference](https://leetcode.com/problems/minimum-absolute-sum-difference/) 40 | - [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/) 41 | - [Find a Peak Element II](https://leetcode.com/problems/find-a-peak-element-ii/) 42 | - [Frequency of the Most Frequent Element](https://leetcode.com/problems/frequency-of-the-most-frequent-element/) 43 | - [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number/) 44 | - [Capacity To Ship Packages Within D Days](https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/) 45 | - [4 Sum](https://leetcode.com/problems/4sum/) 46 | 47 | ## Hard 48 | - [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) 49 | - [Find Minimum in Rotated Sorted Array II](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/) 50 | - [Aggressive cows](https://www.spoj.com/problems/AGGRCOW/) 51 | - [Book allocation](https://www.geeksforgeeks.org/allocate-minimum-number-pages/) 52 | - [Split Array Largest Sum](https://leetcode.com/problems/split-array-largest-sum/) 53 | - [Find in Mountain Array](https://leetcode.com/problems/find-in-mountain-array/) 54 | - [Count smaller number after Self](https://leetcode.com/problems/count-of-smaller-numbers-after-self/) 55 | - [Divide Chocolate Problem](https://curiouschild.github.io/leetcode/2019/06/21/divide-chocolate.html) 56 | -------------------------------------------------------------------------------- /07-sorting/07-sorting.md: -------------------------------------------------------------------------------- 1 | # Videos 2 | - [Bubble Sort](https://youtu.be/F5MZyqRp_IM) 3 | - [Selection Sort](https://youtu.be/Nd4SCCIHFWk) 4 | - [Insertion Sort](https://youtu.be/By_5-RRqVeE) 5 | - [Cycle Sort](https://www.youtube.com/watch?v=JfinxytTYFQ&list=RDCMUCBGOUQHNNtNGcGzVq5rIXjw&start_radio=1&rv=JfinxytTYFQ&t=2) 6 | 7 | # Questions 8 | 9 | ## Easy 10 | - [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/) 11 | - [Majority Element](https://leetcode.com/problems/majority-element/) 12 | - [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) 13 | - [Missing Number](https://leetcode.com/problems/missing-number/) 14 | - [Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays/) 15 | - [Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/) 16 | - [Third Maximum Number](https://leetcode.com/problems/third-maximum-number/) 17 | - [Assign Cookies](https://leetcode.com/problems/assign-cookies/) 18 | - [Array Partition I](https://leetcode.com/problems/array-partition-i/) 19 | - [Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers/) 20 | - [Sort Array By Parity](https://leetcode.com/problems/sort-array-by-parity/) 21 | - [Sort Array By Parity II](https://leetcode.com/problems/sort-array-by-parity-ii/) 22 | - [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle/) 23 | - [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array/) 24 | - [Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order/) 25 | - [Height Checker](https://leetcode.com/problems/height-checker/) 26 | - [Relative Sort Array](https://leetcode.com/problems/relative-sort-array/) 27 | - [Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference/) 28 | - [Rank Transform of an Array](https://leetcode.com/problems/rank-transform-of-an-array/) 29 | - [Sort Integers by The Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits/) 30 | - [How Many Numbers Are Smaller Than the Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/) 31 | - [Maximum Product of Two Elements in an Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/) 32 | - [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/) 33 | - [Make Two Arrays Equal by Reversing Sub-arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays/) 34 | - [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/) 35 | - [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency/) 36 | - [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x/) 37 | - [Find all numbers disappeared in an array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/) 38 | - [Set Mismatch](https://leetcode.com/problems/set-mismatch/) 39 | - [2Sum](https://leetcode.com/problems/two-sum/) 40 | 41 | ## Medium 42 | - [3Sum](https://leetcode.com/problems/3sum/) 43 | - [3Sum Closest](https://leetcode.com/problems/3sum-closest/) 44 | - [4Sum](https://leetcode.com/problems/4sum/) 45 | - [Group Anagrams](https://leetcode.com/problems/group-anagrams/) 46 | - [Merge Intervals](https://leetcode.com/problems/merge-intervals/) 47 | - [Sort Colors](https://leetcode.com/problems/sort-colors/) 48 | - [Insertion Sort List](https://leetcode.com/problems/insertion-sort-list/) 49 | - [Sort List](https://leetcode.com/problems/sort-list/) 50 | - [Largest Number](https://leetcode.com/problems/largest-number/) 51 | - [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/) 52 | - [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number/) 53 | - [Find all Duplicates in an array](https://leetcode.com/problems/find-all-duplicates-in-an-array/) 54 | 55 | ## Hard 56 | - [First missing Positive](https://leetcode.com/problems/first-missing-positive/) 57 | -------------------------------------------------------------------------------- /08-strings/08-strings.md: -------------------------------------------------------------------------------- 1 | # [Video Link](https://youtu.be/zL1DPZ0Ovlo) 2 | 3 | # Problems 4 | 5 | ## Easy 6 | 7 | - [Defanging an Ip address](https://leetcode.com/problems/defanging-an-ip-address/) 8 | - [Shuffle String](https://leetcode.com/problems/shuffle-string/) 9 | - [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation/) 10 | - [Count Items Matching a rule](https://leetcode.com/problems/count-items-matching-a-rule/) 11 | - [Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence/) 12 | - [Check if two strings are equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/) 13 | - [To Lower Case](https://leetcode.com/problems/to-lower-case/) 14 | - [Determine if string halves are alike](https://leetcode.com/problems/determine-if-string-halves-are-alike/) 15 | - [Decrypt String from Alphabet to Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) 16 | - [Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word/) 17 | - [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin/) 18 | - [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii/) 19 | - [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title/) 20 | - [Implement strStr()](https://leetcode.com/problems/implement-strstr/) 21 | - [Long Pressed Name](https://leetcode.com/problems/long-pressed-name/) 22 | - [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) 23 | - [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii/) 24 | - [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) 25 | - [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring/) 26 | - [Check if Binary String Has at Most One Segment of Ones](https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones/) 27 | - [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately/) 28 | - [Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word/) 29 | 30 | ## Medium 31 | - [Jump Game VII](https://leetcode.com/problems/jump-game-vii/) 32 | - [Split Two Strings to Make Palindrome](https://leetcode.com/problems/split-two-strings-to-make-palindrome/) 33 | - [Number of Ways to Split a String](https://leetcode.com/problems/number-of-ways-to-split-a-string/) 34 | - [Sentence Similarity III](https://leetcode.com/problems/sentence-similarity-iii/) 35 | - [Repeated String Match](https://leetcode.com/problems/repeated-string-match/) 36 | - [Next Greater Element III](https://leetcode.com/problems/next-greater-element-iii/) 37 | - [Maximum Number of Removable Characters](https://leetcode.com/problems/maximum-number-of-removable-characters/) 38 | - [Swap Adjacent in LR String](https://leetcode.com/problems/swap-adjacent-in-lr-string/) 39 | - [Multiply Strings](https://leetcode.com/problems/multiply-strings/) 40 | - [Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii/) 41 | - [Minimum Length of String After Deleting Similar Ends](https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends/) 42 | - [Number of Substrings With Only 1s](https://leetcode.com/problems/number-of-substrings-with-only-1s/) 43 | - [Count Number of Homogenous Substrings](https://leetcode.com/problems/count-number-of-homogenous-substrings/) 44 | - [Get Equal Substrings Within Budget](https://leetcode.com/problems/get-equal-substrings-within-budget/) 45 | - [Shifting Letters](https://leetcode.com/problems/shifting-letters/) 46 | - [Minimum Time Difference](https://leetcode.com/problems/minimum-time-difference/) 47 | - [Find Kth Bit in Nth Binary String](https://leetcode.com/problems/find-kth-bit-in-nth-binary-string/) 48 | - [Camelcase Matching](https://leetcode.com/problems/camelcase-matching/) 49 | - [Print Words Vertically](https://leetcode.com/problems/print-words-vertically/) 50 | 51 | 52 | ## Hard 53 | 54 | - [Valid Number](https://leetcode.com/problems/valid-number/) 55 | - [Regular Expression Matching](https://leetcode.com/problems/regular-expression-matching/) 56 | - [Last Substring in Lexicographical Order](https://leetcode.com/problems/last-substring-in-lexicographical-order/) 57 | - [Basic Calculator](https://leetcode.com/problems/basic-calculator/) 58 | - [Minimum Number of Operations to Make String Sorted](https://leetcode.com/problems/minimum-number-of-operations-to-make-string-sorted/) 59 | - [Check If String Is Transformable With Substring Sort Operations](https://leetcode.com/problems/check-if-string-is-transformable-with-substring-sort-operations/) 60 | - [Orderly Queue](https://leetcode.com/problems/orderly-queue/) 61 | - [Special Binary String](https://leetcode.com/problems/special-binary-string/) 62 | 63 | # Additionally 64 | 65 | - [Click "Show problem tags" and do questions that have tags for things we have learnt so far only.](https://leetcode.com/tag/string/) 66 | -------------------------------------------------------------------------------- /09-patterns/09-patterns.md: -------------------------------------------------------------------------------- 1 | Pattern Questions 2 | 3 | Print these patterns using loops: 4 | 5 | ```text 6 | 7 | 1. ***** 8 | ***** 9 | ***** 10 | ***** 11 | ***** 12 | 13 | 14 | 2. * 15 | ** 16 | *** 17 | **** 18 | ***** 19 | 20 | 21 | 3. ***** 22 | **** 23 | *** 24 | ** 25 | * 26 | 27 | 28 | 4. 1 29 | 1 2 30 | 1 2 3 31 | 1 2 3 4 32 | 1 2 3 4 5 33 | 34 | 35 | 5. * 36 | ** 37 | *** 38 | **** 39 | ***** 40 | **** 41 | *** 42 | ** 43 | * 44 | 45 | 46 | 6. * 47 | ** 48 | *** 49 | **** 50 | ***** 51 | 52 | 53 | 7. ***** 54 | **** 55 | *** 56 | ** 57 | * 58 | 59 | 60 | 8. * 61 | *** 62 | ***** 63 | ******* 64 | ********* 65 | 66 | 67 | 9. ********* 68 | ******* 69 | ***** 70 | *** 71 | * 72 | 73 | 74 | 10. * 75 | * * 76 | * * * 77 | * * * * 78 | * * * * * 79 | 80 | 81 | 11. * * * * * 82 | * * * * 83 | * * * 84 | * * 85 | * 86 | 87 | 88 | 12. * * * * * 89 | * * * * 90 | * * * 91 | * * 92 | * 93 | * 94 | * * 95 | * * * 96 | * * * * 97 | * * * * * 98 | 99 | 100 | 13. * 101 | * * 102 | * * 103 | * * 104 | ********* 105 | 106 | 107 | 14. ********* 108 | * * 109 | * * 110 | * * 111 | * 112 | 113 | 114 | 15. * 115 | * * 116 | * * 117 | * * 118 | * * 119 | * * 120 | * * 121 | * * 122 | * 123 | 124 | 125 | 16. 1 126 | 1 1 127 | 1 2 1 128 | 1 3 3 1 129 | 1 4 6 4 1 130 | 131 | 132 | 17. 1 133 | 212 134 | 32123 135 | 4321234 136 | 32123 137 | 212 138 | 1 139 | 140 | 141 | 18. ********** 142 | **** **** 143 | *** *** 144 | ** ** 145 | * * 146 | * * 147 | ** ** 148 | *** *** 149 | **** **** 150 | ********** 151 | 152 | 153 | 19. * * 154 | ** ** 155 | *** *** 156 | **** **** 157 | ********** 158 | **** **** 159 | *** *** 160 | ** ** 161 | * * 162 | 163 | 164 | 20. **** 165 | * * 166 | * * 167 | * * 168 | **** 169 | 170 | 21. 1 171 | 2 3 172 | 4 5 6 173 | 7 8 9 10 174 | 11 12 13 14 15 175 | 176 | 22. 1 177 | 0 1 178 | 1 0 1 179 | 0 1 0 1 180 | 1 0 1 0 1 181 | 182 | 23. * * 183 | * * * * 184 | * * * 185 | 186 | 24. * * 187 | ** ** 188 | * * * * 189 | * * * * 190 | * ** * 191 | * ** * 192 | * * * * 193 | * * * * 194 | ** ** 195 | * * 196 | 197 | 25. ***** 198 | * * 199 | * * 200 | * * 201 | ***** 202 | 203 | 26. 1 1 1 1 1 1 204 | 2 2 2 2 2 205 | 3 3 3 3 206 | 4 4 4 207 | 5 5 208 | 6 209 | 210 | 27. 1 2 3 4 17 18 19 20 211 | 5 6 7 14 15 16 212 | 8 9 12 13 213 | 10 11 214 | 215 | 28. * 216 | * * 217 | * * * 218 | * * * * 219 | * * * * * 220 | * * * * 221 | * * * 222 | * * 223 | * 224 | 225 | 29. 226 | * * 227 | ** ** 228 | *** *** 229 | **** **** 230 | ********** 231 | **** **** 232 | *** *** 233 | ** ** 234 | * * 235 | 236 | 30. 1 237 | 2 1 2 238 | 3 2 1 2 3 239 | 4 3 2 1 2 3 4 240 | 5 4 3 2 1 2 3 4 5 241 | 242 | 243 | 31. 4 4 4 4 4 4 4 244 | 4 3 3 3 3 3 4 245 | 4 3 2 2 2 3 4 246 | 4 3 2 1 2 3 4 247 | 4 3 2 2 2 3 4 248 | 4 3 3 3 3 3 4 249 | 4 4 4 4 4 4 4 250 | 251 | 32. E 252 | D E 253 | C D E 254 | B C D E 255 | A B C D E 256 | 257 | 33. a 258 | B c 259 | D e F 260 | g H i J 261 | k L m N o 262 | 263 | 34. E D C B A 264 | D C B A 265 | C B A 266 | B A 267 | A 268 | 269 | 35. 1 1 270 | 12 21 271 | 123 321 272 | 12344321 273 | ``` 274 | -------------------------------------------------------------------------------- /10-recursion/10-recursion.md: -------------------------------------------------------------------------------- 1 | # Videos 2 | - [Introduction to Recursion](https://youtu.be/M2uO2nMT0Bk) 3 | 4 | # Problems 5 | 6 | ## Easy 7 | - [Sum Triangle from Array](https://www.geeksforgeeks.org/sum-triangle-from-array/) `GFG` 8 | - [Maximum and Minimum value in an array](https://www.geeksforgeeks.org/recursive-programs-to-find-minimum-and-maximum-elements-of-array/) `GFG` 9 | - [First Uppercase Letter in a String](https://www.geeksforgeeks.org/first-uppercase-letter-in-a-string-iterative-and-recursive/) `GFG` 10 | - [Reverse String](https://leetcode.com/problems/reverse-string/) `leetcode` 11 | - [Fibonacci Number](https://leetcode.com/problems/fibonacci-number/) `leetcode` 12 | - [Length of string using Recursion](https://www.geeksforgeeks.org/program-for-length-of-a-string-using-recursion/) `GFG` 13 | - [Recursive Bubble Sort](https://www.geeksforgeeks.org/recursive-bubble-sort/) `GFG` 14 | - [Recursive Insertion Sort](https://www.geeksforgeeks.org/recursive-insertion-sort/) `GFG` 15 | - [Sum of digit of a number using Recursion](https://www.geeksforgeeks.org/sum-digit-number-using-recursion/) `GFG` 16 | - [Product of two numbers using Recursion](https://www.geeksforgeeks.org/product-2-numbers-using-recursion/) `GFG` 17 | - [Check Prime or not](https://www.geeksforgeeks.org/recursive-program-prime-number/) `GFG` 18 | - [Sum of Natural numbers using Recursion](https://www.geeksforgeeks.org/sum-of-natural-numbers-using-recursion/) `GFG` 19 | - [Power of Two](https://leetcode.com/problems/power-of-two/) `leetcode` 20 | - [Power of Three](https://leetcode.com/problems/power-of-three/) `leetcode` 21 | - [Power of Four](https://leetcode.com/problems/power-of-four/) `leetcode` 22 | - Write a recursive function for given n and a to determine x: 23 | ```java 24 | n = a ^ x 25 | a = 2, 3, 4 26 | (2 ^ -31) <= n <= (2 ^ 31) - 1 27 | ``` 28 | - [Write a recursive function that returns the factorial of a number.](https://www.hackerrank.com/challenges/30-recursion/problem) `HackerRank` 29 | - [Write a recursive function to check whether an array is sorted or not.](https://www.geeksforgeeks.org/program-check-array-sorted-not-iterative-recursive) `GFG` 30 | - [Number of Steps to Reduce a Number to Zero.](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/) `leetcode` 31 | 32 | ## Medium 33 | - [Find Kth Bit in Nth Binary String](https://leetcode.com/problems/find-kth-bit-in-nth-binary-string/) `leetcode` 34 | - [K-th Symbol in Grammar](https://leetcode.com/problems/k-th-symbol-in-grammar/) `leetcode` 35 | - [Count Good Numbers](https://leetcode.com/problems/count-good-numbers/) `leetcode` 36 | - [Pow(x, n)](https://leetcode.com/problems/powx-n/) `leetcode` 37 | - [Minimum Non-Zero Product of the Array Elements](https://leetcode.com/problems/minimum-non-zero-product-of-the-array-elements/) `leetcode` 38 | 39 | ## Hard 40 | - [Parsing A Boolean Expression](https://leetcode.com/problems/parsing-a-boolean-expression/) `leetcode` 41 | - [Special Binary String](https://leetcode.com/problems/special-binary-string/) `leetcode` 42 | - [Permutation Sequence](https://leetcode.com/problems/permutation-sequence/) `leetcode` 43 | - [Basic Calculator](https://leetcode.com/problems/basic-calculator/) `leetcode` 44 | - [Integer to English Words](https://leetcode.com/problems/integer-to-english-words/) `leetcode` 45 | - [Maximize Number of Nice Divisors](https://leetcode.com/problems/maximize-number-of-nice-divisors/) `leetcode` 46 | -------------------------------------------------------------------------------- /11-bitwise/11-bitwise.md: -------------------------------------------------------------------------------- 1 | # [Video link](https://youtu.be/fzip9Aml6og) 2 | 3 | ## Problems 4 | 5 | ## Easy 6 | - [Add Binary](https://leetcode.com/problems/add-binary/) 7 | - [Single Number](https://leetcode.com/problems/single-number/) 8 | - [Reverse Bits](https://leetcode.com/problems/reverse-bits/) 9 | - [Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/) 10 | - [Counting Bits](https://leetcode.com/problems/counting-bits/) 11 | - [Binary Watch](https://leetcode.com/problems/binary-watch/) 12 | - [Hamming Distance](https://leetcode.com/problems/hamming-distance/) 13 | - [Number Complement](https://leetcode.com/problems/number-complement/) 14 | - [Set Mismatch](https://leetcode.com/problems/set-mismatch/) 15 | - [Binary Number with Alternating Bits](https://leetcode.com/problems/binary-number-with-alternating-bits/) 16 | - [Prime Number of Set Bits in Binary Representation](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation/) 17 | - [Binary Gap](https://leetcode.com/problems/binary-gap/) 18 | - [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/) 19 | - [Sort Integers by The Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits/) 20 | - [XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array/) 21 | - [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings/) 22 | - [Decode XORed Array](https://leetcode.com/problems/decode-xored-array/) 23 | - [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals/) 24 | - [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring/) 25 | 26 | ## Medium 27 | - [Subsets](https://leetcode.com/problems/subsets/) 28 | - [Subsets II](https://leetcode.com/problems/subsets-ii/) 29 | - [Single Number II](https://leetcode.com/problems/single-number-ii/) 30 | - [Divide Two Integers](https://leetcode.com/problems/divide-two-integers/) 31 | - [Gray Code](https://leetcode.com/problems/gray-code/) 32 | - [Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences/) 33 | 34 | # Additionally 35 | - Click on [*Show problem tags*](https://leetcode.com/tag/bit-manipulation/) and do the questions that contains tags of topics we have covered so far. 36 | -------------------------------------------------------------------------------- /12-math/12-math.md: -------------------------------------------------------------------------------- 1 | # [Video link](https://youtu.be/lmSpZ0bjCyQ) 2 | 3 | ## Problems 4 | - Click on [*Show problem tags*](https://leetcode.com/tag/math/) and do the questions that contains tags of topics we have covered so far. 5 | --------------------------------------------------------------------------------