├── Cloud
├── CONTRIBUTING.md
├── OOP's
├── Design a class
├── Constructor
├── Constructor Overloading
└── Addition
├── recursion
├── decimaltobinary.exe
├── theSequence
├── Tower Of Hanoi
├── fibonacci
├── Find nCr
├── RecursivePower
├── Print 1 To N Without Loop
├── Sum of Digits of a Number
├── Count Total Digits in a Number
├── Recursively Sum N Numbers
├── GCD
├── Factorial Using Recursion
├── printArrayRecursively
├── decimaltobinary.cpp
└── Check Palindrome
├── IBM-SE-Intern
├── divby7.py
├── xxyy_pattern.java
└── Even_odd.java
├── Arrays & String
├── findPattern,java
├── binary_to_decimal.java
├── Decimal number to binary number.java
├── Reverse String.java
├── arraySum.java
├── Largest Element in Array.java
├── arraySortedOrNot.java
├── Check Palindrome.java
├── Maximum Area Rectangle.java
├── Average.java
├── Count Odd Even.java
├── Find distinct elements.java
├── Matrix Interchange.java
├── Predict the Column.java
├── Almost Equal.java
├── Find one extra character.java
├── Count the Specials.java
├── Next Permutation.cpp
├── The Pattern Matcher,java
└── Consonants and Vowels check.java
├── Introduction, Variables and Operators
├── 9_Bitwise_Right_Shift.java
├── 10_Day_before_N_days.java
├── 8_Sum_of_N_Numbers.java
├── 11_Last_Digit_of_a_number.java
├── 7_Swap_The_Numbers.java
├── 12_AP_Term.java
├── 2_The_New_Line.Java
├── 6_Precise_Fomat.java
├── 14_logical Operators.java
├── 3_Learn_to_Comment.Java
├── 5_Data_Types.java
├── 4_Taking_input.java
├── 1_Start Coding_Java.java
├── 15_Bitwise_Operators.java
└── 13_GP_Term.java
├── Arrays_Basic_DS
├── Sum of Array Elements
├── Array Delete And Shift,java
├── Get Element At Index
├── Array Update At Index,java
├── Maximum and Minimum In Array
├── Array insert at end
├── Find Immediate Smaller Than X
├── Reverse The Array
├── Count Elements Greater Than X
├── Count Smaller Than X
├── Find Immediate Greater Than X
├── Array insert at index
├── Is Array Sorted
├── Who has the majority.java
├── Rotate Array
└── Mean And Median of Array
├── Searching
├── Search an Element in an array.java
├── Square root of a number.java
├── Searching an element in a sorted array.java
├── Count 1's in binary array.java
├── search insert position.java
├── Find Smallest Letter Greater Than Target.java
├── Binary Search.java
├── Majority Element.java
└── Search in Rotated Sorted Array.java
├── README.md
├── soring
├── selectionSort.cpp
├── Bubble Sort.java
├── Insertion.java
├── SelectionSort.java
└── quickSort.java
├── Flow Control, Loops & Function
├── ForLoopprimeCheck.Java
├── Factorial.java
├── Divisor.java
├── TableDifference.java
├── FirstDigitofaNumber.java
├── FibonacciNumber.java
├── GCD.java
├── CountDigits.java
├── LCM.java
├── LeapYear.java
├── CheckPrime.java
└── Calculator.java
├── Backtracking
├── StringPermutations.cpp
└── PhoneNumberLetterCombinations.cpp
├── moveToFront.java
├── CyclicSort.java
├── LICENSE.md
├── Backtracking Problems
├── NQueens.java
└── Remove Invalid Parentheses.java
├── print all palindrome of string.cpp
├── N queen problem .cpp
├── Singlylinkedlist.java
├── Starting.txt
└── ui
└── style.css
/Cloud:
--------------------------------------------------------------------------------
1 | https://drive.google.com/file/d/1Y5UHcbZF--6XXFIlQ0bhuw9a6tB1iaaA/view?usp=sharing
2 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 |
How to contribute ?
2 |
3 |
4 | Merge any DSA problems
5 | any language
6 |
--------------------------------------------------------------------------------
/OOP's/Design a class:
--------------------------------------------------------------------------------
1 | class MyClass{
2 | void display(){
3 | System.out.println("Hello World");
4 |
5 | }
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/OOP's/Constructor:
--------------------------------------------------------------------------------
1 | // code here
2 |
3 | class User{
4 | String name;
5 | public User(){
6 | this.name="Default";
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/recursion/decimaltobinary.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manohar-mj/Complete-Interview-Preparation---Self-Paced/HEAD/recursion/decimaltobinary.exe
--------------------------------------------------------------------------------
/recursion/theSequence:
--------------------------------------------------------------------------------
1 | int theSequence(int N)
2 | {
3 | //Your code hereif
4 | if(N==0)
5 | return 1;
6 | return N+N*(theSequence(N-1));
7 | }
8 |
--------------------------------------------------------------------------------
/IBM-SE-Intern/divby7.py:
--------------------------------------------------------------------------------
1 | def divisibleBy5(n):
2 | res=int(n)
3 | if res%5 ==0:
4 | return '1'
5 | else: return '0'
6 | n="556"
7 | print(divisibleBy5(n))
--------------------------------------------------------------------------------
/Arrays & String/findPattern,java:
--------------------------------------------------------------------------------
1 | public static int findPattern(String s, String p){
2 | // code here
3 | if(s.contains(p))
4 | return s.indexOf(p);
5 | else return -1;
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/recursion/Tower Of Hanoi:
--------------------------------------------------------------------------------
1 | if(N==0)
2 | return 0;
3 | toh(N-1,from,aux,to);
4 | cout<<"move disk " << N << " from rod " << from << " to rod " << to<< endl;
5 | toh(N-1,aux,to,from);
6 | return (long)pow(2,N)-1;
7 |
--------------------------------------------------------------------------------
/OOP's/Constructor Overloading:
--------------------------------------------------------------------------------
1 |
2 | class User{
3 | String name;
4 | public User(){
5 | name="Default";
6 | }
7 | public User(String name){
8 | this.name=name;
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/Arrays & String/binary_to_decimal.java:
--------------------------------------------------------------------------------
1 | // User function Template for Java
2 |
3 | class Solution {
4 | public int binary_to_decimal(String str) {
5 | // Code herern
6 | return Integer.parseInt(str,2);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Introduction, Variables and Operators/9_Bitwise_Right_Shift.java:
--------------------------------------------------------------------------------
1 | public static void utility(int a, int b){
2 |
3 | //just complete below statement
4 | int ans = a>>b;
5 |
6 | //print the result
7 | System.out.println(ans);
8 | }
9 |
--------------------------------------------------------------------------------
/recursion/fibonacci:
--------------------------------------------------------------------------------
1 |
2 | class Solution
3 | {
4 | static int fibonacci(int n)
5 | {
6 | // your code here
7 | if(n==0 && n==1)
8 | return n;
9 | return fibonacci(n-1)+fibonacci(n-2);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Introduction, Variables and Operators/10_Day_before_N_days.java:
--------------------------------------------------------------------------------
1 | void utility(int d, int n){
2 |
3 | //write your code here
4 | int ans=d-n%7;
5 | if (ans<0){
6 | ans=ans*-1;
7 | ans++;
8 | }
9 | cout<max){
6 | max=arr[i];
7 | }
8 | }
9 | return max;
10 | }
11 |
--------------------------------------------------------------------------------
/Introduction, Variables and Operators/12_AP_Term.java:
--------------------------------------------------------------------------------
1 | public static void utility(int a, int d, int n){
2 | //Complete the code above
3 | int ans = a+(n-1)*d;
4 | //Complete the code above
5 |
6 | //The line below prints the output. Don't change it!
7 | System.out.println(ans);
8 | }
9 |
--------------------------------------------------------------------------------
/OOP's/Addition:
--------------------------------------------------------------------------------
1 | // create a class addition
2 | // with a static function add
3 | // this should return the sum of
4 | // two values(a,b) passed in the parameter
5 | class Addition{
6 | int a,b;
7 | public static int add(int a,int b){
8 | return a+b;
9 | }
10 | }
11 | // code here
12 |
--------------------------------------------------------------------------------
/Searching/Search an Element in an array.java:
--------------------------------------------------------------------------------
1 | int search(int arr[], int N, int X)
2 | {
3 |
4 | // Your code herer
5 | for(int i=0;i=0){
7 | s+=numbers[i];
8 | c++;
9 |
10 |
11 | }
12 | }
13 | return s/c;
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/Searching/Count 1's in binary array.java:
--------------------------------------------------------------------------------
1 | int countOnes(int arr[], int N)
2 | {
3 |
4 | // Your code here
5 | int count=0;
6 | for(int i=0;ii){
7 | return arr[i];
8 | }
9 |
10 | return -1;
11 | // Your code here
12 | // if (i>=n){
13 | // return -1;
14 | // }
15 | // return arr[i];
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Complete-Interview-Preparation---Self-Paced
2 |
3 | add any DSA or interview questions
4 | ===============================================
5 |
6 |
7 | Any Language
8 |
9 | ===============================================
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Arrays_Basic_DS/Array Update At Index,java:
--------------------------------------------------------------------------------
1 | class UpdateArray
2 | {
3 | // Complete the function
4 | // arr[]: input array
5 | // index: input index
6 | // element: element to be updated
7 | public static void updateArray(int arr[], int index, int element)
8 | {
9 | // Update the element at index
10 |
11 | arr[index]=arr[element];
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Arrays_Basic_DS/Maximum and Minimum In Array:
--------------------------------------------------------------------------------
1 | class Get
2 | {
3 | public static int maximumElement(int arr[],int n)
4 | {
5 |
6 | return Arrays.stream(arr).max().getAsInt();
7 |
8 | }
9 |
10 | public static int minimumElement(int arr[],int n)
11 | {
12 | // YOUR code here
13 |
14 | return Arrays.stream(arr).min().getAsInt();
15 | }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/Arrays_Basic_DS/Array insert at end:
--------------------------------------------------------------------------------
1 | class Insert
2 | {
3 | // You only need to insert the given element at
4 | // the end, i.e., at index sizeOfArray - 1. You may
5 | // assume that the array already has sizeOfArray - 1
6 | // elements.
7 | public void insertAtEnd(int arr[],int sizeOfArray,int element)
8 | {
9 | //Your code here
10 | arr[sizeOfArray-1]=element;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Arrays_Basic_DS/Find Immediate Smaller Than X:
--------------------------------------------------------------------------------
1 | class Solution
2 | {
3 | // Complete the function
4 | public static int immediateSmaller(int arr[], int n, int x)
5 | {
6 | // Your code here
7 | int ans=-1;
8 | for(int i=0;ians){
10 | ans=arr[i];
11 | }
12 | }
13 | return ans;
14 | }
15 | };
16 |
--------------------------------------------------------------------------------
/Arrays_Basic_DS/Reverse The Array:
--------------------------------------------------------------------------------
1 |
2 | class Get {
3 | public static void reverseArray(int arr[], int n) {
4 | // Your code here
5 | int h=n-1;
6 | int l=0;
7 |
8 | for(int i=1;itarget){
10 | high = mid-1;
11 | }else
12 | low = mid+1;
13 | }
14 | return low;
15 | }
16 | }
--------------------------------------------------------------------------------
/Arrays_Basic_DS/Count Elements Greater Than X:
--------------------------------------------------------------------------------
1 |
2 | class Solution
3 | {
4 | // arr[]: input array
5 | // n: size of the array
6 | // x: element for which you need to return the count
7 | public static int greaterThanX(int arr[], int n, int x)
8 | {
9 | // Your code here
10 | int count=0;
11 | for(int i=0;ix){
13 | count++;
14 | }
15 | }
16 | return count;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Arrays_Basic_DS/Count Smaller Than X:
--------------------------------------------------------------------------------
1 |
2 | // arr[]: input array
3 | // n: size of array
4 | // x: element for which you need to find smaller than x
5 | class Solution
6 | {
7 | public static int smallerThanX(int arr[], int n, int x)
8 | {
9 | // Your code here
10 | int count=0;
11 | for(int i=1;iarr[i]){
13 | count++;
14 | }
15 | return count;
16 | }
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Flow Control, Loops & Function/ForLoopprimeCheck.Java:
--------------------------------------------------------------------------------
1 | class Geeks {
2 | static void isPrime(int n) {
3 | if(n==1){
4 | System.out.println("No");
5 | return;
6 | }
7 | for (int i = 2; i <= Math.sqrt(n); i++) {
8 | // Your code here
9 | if(n%i==0){
10 | System.out.println("No");
11 | return;
12 | }
13 | }
14 |
15 | System.out.println("Yes");
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Arrays & String/Find distinct elements.java:
--------------------------------------------------------------------------------
1 | static int distinct(int arr[], int n) {
2 | // code herent
3 | int c=0;
4 | boolean isDistinct=true;
5 |
6 | for(int i=0;i=0;j--){
8 | if(arr[i]==arr[j]){
9 | isDistinct=false;
10 | break;
11 | }
12 | }
13 | if(isDistinct==true){
14 | c++;
15 | }
16 | isDistinct=true;
17 | }
18 | return c;
19 |
--------------------------------------------------------------------------------
/Arrays & String/Matrix Interchange.java:
--------------------------------------------------------------------------------
1 | static void interchange(int a[][],int r, int c){
2 |
3 | // Your code here
4 | int temp;
5 | for(int i=0;i
4 | using namespace std;
5 |
6 | int find(int decimal_number)
7 | {
8 | if (decimal_number == 0)
9 | return 0;
10 | else
11 | return (decimal_number % 2 + 10 *
12 | find(decimal_number / 2));
13 | }
14 |
15 | int main()
16 | {
17 | int decimal_number;
18 | cout<<"Enter the no to be converted: ";
19 | cin>>decimal_number;
20 | cout << find(decimal_number);
21 | return 0;
22 | }
--------------------------------------------------------------------------------
/Arrays & String/Predict the Column.java:
--------------------------------------------------------------------------------
1 |
2 | static int columnWithMaxZero(int a[][],int n){
3 |
4 | // Your code herent
5 | int max=0,sum=0,ans=0;
6 |
7 | for(int i=0;imax){
14 | max=sum;
15 | ans=i;
16 | }
17 | sum=0;
18 | }
19 | return ans;
20 | }
21 |
--------------------------------------------------------------------------------
/Introduction, Variables and Operators/5_Data_Types.java:
--------------------------------------------------------------------------------
1 |
2 | class Geeks{
3 |
4 | // Function to do operations with different data types
5 | static void dataTypes(int a, float b, double c, long l, byte d){
6 |
7 | double p = c/b;//c/b
8 | double q = b/a;//b/a
9 | double r = c/a;//c/a
10 | double m = r+l;//r+l
11 | int s = a/d;//a/d
12 |
13 | //Printing all the results
14 | System.out.println(p + " " + q + " " + r + " " + m + " " + s);
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Arrays & String/Almost Equal.java:
--------------------------------------------------------------------------------
1 | static int coutChars(String s1, String s2)
2 | {
3 |
4 | //Your code herent
5 | int ans=0;
6 | int a[]=new int[26];
7 | for(int i=0;i< s1.length();i++)
8 | a[s1.charAt(i)-'a']++;
9 |
10 | for(int i=0;i=end)
6 | return true;
7 | if(s[start] !=s[end]){
8 | return false;
9 | }
10 | fun(s,start+1,end-1);
11 | }
12 | public:
13 | bool isPalin(int N)
14 | {
15 | //Your code here
16 | //You may use a helper function if you like
17 | string s=to_string(N);
18 | return fun(s,0,s.length()-1);
19 |
20 |
21 | }
22 | };
23 |
--------------------------------------------------------------------------------
/soring/Bubble Sort.java:
--------------------------------------------------------------------------------
1 | class Solution
2 |
3 | {
4 | //Function to sort the array using bubble sort algorithm.
5 | public static void bubbleSort(int arr[], int n)
6 | {
7 | //code here
8 | for(int i=0;iarr[j+1])
13 | {
14 | int t=arr[j];
15 | arr[j]=arr[j+1];
16 | arr[j+1]=t;
17 | }
18 | }
19 | }
20 | }
21 | };
22 |
--------------------------------------------------------------------------------
/Arrays_Basic_DS/Find Immediate Greater Than X:
--------------------------------------------------------------------------------
1 | class Solution
2 | {
3 | // Complete the function
4 | public static int immediateGreater(int arr[], int n, int x)
5 | {
6 | // Your code here
7 | int res=0;
8 | int ans=Integer.MAX_VALUE;
9 | for(int i=0;ix){
11 | res=arr[i];
12 | if(res
2 | using namespace std;
3 |
4 |
5 |
6 | int permutation_s(string s, int left, int right){
7 | if(left == right){
8 | cout << s << endl;
9 | return 0;
10 |
11 | }
12 | for(int i=left;i<=right;i++){
13 | swap(s[i], s[left]);
14 | permutation_s(s, left+1, right);
15 | swap(s[i], s[left]);
16 | }
17 |
18 | return 0;
19 | }
20 |
21 | int main() {
22 | string s;
23 | cin >>s;
24 | int right = s.size();
25 | permutation_s(s, 0, right-1);
26 | return 0;
27 | }
--------------------------------------------------------------------------------
/Searching/Find Smallest Letter Greater Than Target.java:
--------------------------------------------------------------------------------
1 | class Solution
2 | {
3 | public char nextGreatestLetter(char[] letters, char target)
4 | {
5 | int start = 0, end = letters.length - 1;
6 |
7 | while (start <= end)
8 | {
9 | int mid = start + (end - start) / 2;
10 | if (target < letters[mid])
11 | {
12 | end = mid - 1;
13 | }
14 | else
15 | {
16 | start = mid + 1;
17 | }
18 | }
19 | return letters[start % letters.length];
20 | }
21 | }
--------------------------------------------------------------------------------
/moveToFront.java:
--------------------------------------------------------------------------------
1 | class Solution {
2 |
3 | public static Node moveToFront(Node head) {
4 |
5 | // code here
6 |
7 | if(head==null||head.next==null)
8 |
9 | {
10 |
11 | return head;
12 |
13 | }
14 |
15 | Node curr = head;
16 |
17 |
18 |
19 | while(curr.next.next!=null)
20 |
21 | {
22 |
23 | curr = curr.next;
24 |
25 | }
26 |
27 | Node res = curr.next;
28 |
29 | curr.next=null;
30 |
31 | res.next=head;
32 |
33 | return res;
34 |
35 |
36 |
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/Arrays & String/Count the Specials.java:
--------------------------------------------------------------------------------
1 | static void countSpecials(int a[], int n, int k){
2 | int f = (int)Math.floor(n/k);
3 | // your code here
4 | int c=0; //count
5 | //int r=0; //repeat
6 | for(int i=0;iindex;i--){
12 | arr[i]=arr[i-1];
13 | }
14 | arr[index]=element;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/Introduction, Variables and Operators/4_Taking_input.java:
--------------------------------------------------------------------------------
1 | class Geeks{
2 |
3 | // Function to take input using Scanner class
4 | static void IOFunction(){
5 | Scanner sc = new Scanner(System.in);
6 | int t = sc.nextInt();
7 |
8 | while(t-- > 0){
9 |
10 | // Your code here
11 | int a=sc.nextInt();
12 | float b=sc.nextFloat();
13 | Long c=sc.nextLong();
14 | int d=sc.nextByte();
15 | sc.nextLine();
16 | String s=sc.nextLine();
17 | System.out.println(a+"\n"+b+"\n"+c+"\n"+d+"\n"+s+"\n");
18 |
19 |
20 | }
21 |
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/soring/Insertion.java:
--------------------------------------------------------------------------------
1 | class Solution
2 | {
3 | static void insert(int arr[],int i)
4 | {
5 | // Your code here
6 | while(i>0 && arr[i-1]>arr[i])
7 | {
8 | int temp=arr[i];
9 | arr[i]=arr[i-1];
10 | arr[i-1]=temp;
11 | i--;
12 | }
13 |
14 | }
15 | //Function to sort the array using insertion sort algorithm.
16 | public void insertionSort(int arr[], int n)
17 | {
18 | //code here
19 | for(int i=1;iarr[i])
22 | {
23 | insert(arr,i);
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/soring/SelectionSort.java:
--------------------------------------------------------------------------------
1 |
2 | class Solution
3 | {
4 | int select(int arr[], int i)
5 | {
6 | // code here such that selectionSort() sorts arr[]
7 |
8 | }
9 |
10 | void selectionSort(int arr[], int n)
11 | {
12 | //code here
13 | for (int i =0; i < n - 1; i++) {
14 |
15 | int minIndex = i;
16 | for (int j = i + 1; j < n; j++){
17 | if(arr[minIndex] > arr[j])
18 | minIndex = j;
19 | }
20 | int temp = arr[minIndex];
21 | arr[minIndex] = arr[i];
22 | arr[i] = temp;
23 | }
24 |
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Arrays & String/Next Permutation.cpp:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | void nextPermutation(vector& ARR)
4 | {
5 | int N=ARR.size();
6 | int i,j;
7 | for(i=N-2;i>=0;i--)
8 | {
9 | if(ARR[i]i;j--)
16 | {
17 | if(ARR[i]=arr[i]){
19 | count2++;
20 | }
21 | }
22 |
23 | if(count1==n-1 || count2==n-1){
24 | return 1;
25 | }else{
26 | return 0;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Arrays & String/The Pattern Matcher,java:
--------------------------------------------------------------------------------
1 | static void follPatt(String s)
2 | {
3 | int count = 0,res=1;
4 | for(int i=0;i0){
24 | res=0;
25 | }
26 |
27 | System.out.println(res);
28 | }
29 |
--------------------------------------------------------------------------------
/Arrays_Basic_DS/Who has the majority.java:
--------------------------------------------------------------------------------
1 | class Solution {
2 | // Function to find element with more appearances between two elements in an
3 | // array.
4 | public int majorityWins(int arr[], int n, int x, int y) {
5 | // code here
6 | int x_count=0,y_count=0,res=0;
7 | for(int i=0;iy_count)
19 | return x;
20 | else
21 | return y;
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Arrays_Basic_DS/Rotate Array:
--------------------------------------------------------------------------------
1 | class Solution
2 | {
3 | //Function to rotate an array by d elements in counter-clockwise direction.
4 |
5 |
6 |
7 | static void rotateArr(int arr[], int d, int n)
8 | {
9 | // add your code here
10 | d=d%n;
11 | reverse(arr,0,d-1);
12 | reverse(arr,d,n-1);
13 | reverse(arr,0,n-1);
14 | }
15 | static void reverse(int arr[],int low,int high)
16 | {
17 | while(low0)
13 | {
14 | ans=ans*n;
15 | n=n-1;
16 | }
17 | return ans;
18 | }
19 |
20 | //{ Driver Code Starts.
21 |
22 | public static void main(String[] args)
23 | {
24 | Scanner scn = new Scanner(System.in);
25 | int t = scn.nextInt();
26 | while(t-- > 0) {
27 | int n = scn.nextInt();
28 | int ans = nFactorial(n);
29 | System.out.println(ans);
30 | }
31 | scn.close();
32 | }
33 | }
34 | // } Driver Code Ends
35 |
--------------------------------------------------------------------------------
/Searching/Binary Search.java:
--------------------------------------------------------------------------------
1 | class binarysearch
2 | {
3 | static int arr[] = {12, 34, 54, 2, 3};
4 |
5 | static int recSearch(int arr[], int l, int r, int x)
6 | {
7 | if (r < l)
8 | return -1;
9 | if (arr[l] == x)
10 | return l;
11 | if (arr[r] == x)
12 | return r;
13 | return recSearch(arr, l+1, r-1, x);
14 | }
15 |
16 | public static void main(String[] args)
17 | {
18 | int x = 3;
19 |
20 | int index = recSearch(arr, 0, arr.length-1, x);
21 | if (index != -1)
22 | System.out.println("Element " + x + " is present at index " +
23 | index);
24 | else
25 | System.out.println("Element " + x + " is not present");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Arrays & String/Consonants and Vowels check.java:
--------------------------------------------------------------------------------
1 |
2 | static void checkString(String s)
3 | {
4 | int v=0;
5 | int c=0;
6 |
7 | //Your code here
8 | char x;
9 | for(int i=0;ic)
23 | System.out.print("Yes");
24 | else if(c>v)
25 | System.out.print("No");
26 | else
27 | System.out.print("Same");
28 |
29 | System.out.println();
30 | }
31 |
--------------------------------------------------------------------------------
/Flow Control, Loops & Function/Divisor.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | class Main {
4 |
5 |
6 | // } Driver Code Ends
7 | //User function Template for Java
8 |
9 | public static void divisor(int n){
10 |
11 | //Write your code here
12 | for(int i=1;i<=n;i++){
13 | if(n%i==0){
14 | System.out.print(i+" ");
15 | }
16 | }
17 |
18 | }
19 |
20 | //{ Driver Code Starts.
21 |
22 | public static void main(String[] args)
23 | {
24 | Scanner scn = new Scanner(System.in);
25 | int t = scn.nextInt();
26 | while(t-- > 0) {
27 | int n = scn.nextInt();
28 | divisor(n);
29 | System.out.println();
30 | }
31 | scn.close();
32 | }
33 | }
34 | // } Driver Code Ends
35 |
--------------------------------------------------------------------------------
/Flow Control, Loops & Function/TableDifference.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | class Main {
4 |
5 |
6 | // } Driver Code Ends
7 | //User function Template for Java
8 |
9 | public static void difference(int n1, int n2){
10 |
11 | //Write your code here
12 | n1=n1-n2;
13 | for(int i=1;i<=10;i++){
14 | System.out.print(n1*i+" ");
15 | }
16 | }
17 |
18 | // { Driver Code Starts.
19 |
20 | public static void main(String[] args)
21 | {
22 | Scanner scn = new Scanner(System.in);
23 | int t = scn.nextInt();
24 | while(t-- > 0) {
25 | int n1 = scn.nextInt();
26 | int n2 = scn.nextInt();
27 | difference(n1, n2);
28 | System.out.println();
29 | }
30 | scn.close();
31 | }
32 | } // } Driver Code Ends
33 |
--------------------------------------------------------------------------------
/Flow Control, Loops & Function/FirstDigitofaNumber.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 |
3 | class GFG{
4 | public static void main(String arg[]) throws IOException{
5 | BufferedReader read = new BufferedReader( new InputStreamReader(System.in));
6 |
7 | int t = Integer.parseInt(read.readLine());
8 | while(t-- > 0){
9 | int n = Integer.parseInt(read.readLine());
10 |
11 | int answer = firstDigit(n);
12 | System.out.println(answer);
13 | }
14 | }
15 |
16 |
17 | // } Driver Code Ends
18 | //User function Template for Java
19 |
20 |
21 | // Complete the function
22 | public static int firstDigit(int n){
23 | // code herern n;
24 | int temp=0;
25 | while(n!=0){
26 | temp=n;
27 | n=n/10;
28 | }
29 | return temp;
30 |
31 | }
32 |
33 | //{ Driver Code Starts.
34 | }
35 | // } Driver Code Ends
36 |
--------------------------------------------------------------------------------
/Flow Control, Loops & Function/FibonacciNumber.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | class Main {
4 |
5 |
6 | // } Driver Code Ends
7 | //User function Template for Java
8 |
9 | public static int fibonacci(int n){
10 |
11 | //Write your code here to calculate
12 | //to calculate the nth fibonacci number
13 | int a=1;
14 | int b=1;
15 | int c=0;
16 | for(int i=3;i<=n;i++)
17 | {
18 | c=a+b;
19 | a=b;
20 | b=c;
21 | }
22 | return c;
23 |
24 | }
25 |
26 | //{ Driver Code Starts.
27 |
28 | public static void main(String[] args)
29 | {
30 | Scanner scn = new Scanner(System.in);
31 | int t = scn.nextInt();
32 | while(t-- > 0) {
33 | int n = scn.nextInt();
34 | int ans = fibonacci(n);
35 | System.out.println(ans);
36 | }
37 | scn.close();
38 | }
39 | }
40 | // } Driver Code Ends
41 |
--------------------------------------------------------------------------------
/Flow Control, Loops & Function/GCD.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | class Main {
4 |
5 |
6 | // } Driver Code Ends
7 | //User function Template for Java
8 |
9 | public static int gcd(int a, int b){
10 |
11 |
12 | //code here to calculate and return gcd of a and b
13 | int ans=1;
14 | int x=Math.min(a,b);
15 | for(int i=1;i<=x;i++){
16 | if(a%i==0 && b%i==0){
17 | ans=i;
18 | }
19 | }
20 | return ans;
21 |
22 |
23 | }
24 |
25 | //{ Driver Code Starts.
26 |
27 | public static void main(String[] args)
28 | {
29 | Scanner scn = new Scanner(System.in);
30 | int t = scn.nextInt();
31 | while(t-- > 0) {
32 | int A = scn.nextInt();
33 | int B = scn.nextInt();
34 | int ans = gcd(A,B);
35 | System.out.println(ans);
36 | }
37 | scn.close();
38 | }
39 | }
40 | // } Driver Code Ends
41 |
--------------------------------------------------------------------------------
/Backtracking/PhoneNumberLetterCombinations.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int solve(string digits, int index, string maping_values[], string output){
5 | // base case
6 | if(digits.length() == output.length()){
7 | cout << output << endl;
8 | return 0;
9 | }
10 | int digit = digits[index] - '0';
11 | string char_digits = maping_values[digit];
12 | for(int i=0;i> digits;
24 | string maping_values[] = {"", "", "abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
25 | solve(digits, 0, maping_values, "");
26 | return 0;
27 | /*
28 | 23
29 | ad
30 | ae
31 | af
32 | bd
33 | be
34 | bf
35 | cd
36 | ce
37 | cf
38 | */
39 | }
40 |
--------------------------------------------------------------------------------
/Flow Control, Loops & Function/CountDigits.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | class Main {
4 |
5 |
6 | // } Driver Code Ends
7 | //User function Template for Java
8 |
9 | public static void countDigits(int n){
10 |
11 | //write your code here
12 | //print number of digits in n
13 | // System.out.println(n.length());
14 | // int count=0;
15 | // if(n>0){
16 | // n=n/10;
17 | // count=count+1;
18 | // }
19 | // System.out.print(count);
20 | System.out.print(String.valueOf(n).length());
21 | }
22 |
23 | //{ Driver Code Starts.
24 |
25 | public static void main(String[] args)
26 | {
27 | Scanner scn = new Scanner(System.in);
28 | int t = scn.nextInt();
29 | while(t-- > 0) {
30 | int n = scn.nextInt();
31 | countDigits(n);
32 | System.out.println();
33 | }
34 | scn.close();
35 | }
36 | }
37 | // } Driver Code Ends
38 |
--------------------------------------------------------------------------------
/Flow Control, Loops & Function/LCM.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | class Main {
4 |
5 |
6 | // } Driver Code Ends
7 | //User function Template for Java
8 |
9 | public static int LCM(int a, int b){
10 |
11 | //write your code here
12 | //return LCM of a and bnt
13 | int x=Math.max(a,b);
14 | int y=a*b;
15 | int ans=x;
16 | for(int i=x;i<=y;i++){
17 | if(i%a==0 & i%b==0){
18 | ans=i;
19 | break;
20 | }
21 | }
22 | return ans;
23 |
24 |
25 | }
26 |
27 | //{ Driver Code Starts.
28 |
29 | public static void main(String[] args)
30 | {
31 | Scanner scn = new Scanner(System.in);
32 | int t = scn.nextInt();
33 | while(t-- > 0) {
34 | int a = scn.nextInt();
35 | int b = scn.nextInt();
36 | System.out.println(LCM(a, b));
37 | }
38 | scn.close();
39 | }
40 | }
41 | // } Driver Code Ends
42 |
--------------------------------------------------------------------------------
/CyclicSort.java:
--------------------------------------------------------------------------------
1 |
2 | import java.util.*;
3 |
4 | public class CyclicSort {
5 |
6 | public static void main(String[] args) {
7 | Scanner sc = new Scanner(System.in);
8 |
9 | int[] arr = {3, 5, 2, 1, 4};
10 | // always remember it should be continous
11 |
12 | sorting(arr);
13 | System.out.println(Arrays.toString(arr));
14 |
15 | }
16 |
17 | // Algo :-
18 | // 1. Start looping from i
19 | // 2. Put it at corrct index
20 | // 3. Only move i when the element at i is sorted
21 |
22 | static void sorting(int[] arr) {
23 | int i = 0;
24 | while (i < arr.length) {
25 | int correctInd = arr[i] - 1;
26 | // this should be the correct index
27 |
28 | if (arr[i] != arr[correctInd]) {
29 | swap(arr, i, correctInd);
30 | } else {
31 | i++;
32 | }
33 | }
34 | }
35 |
36 | static void swap(int[] arr, int first, int second) {
37 | int temp = arr[first];
38 | arr[first] = arr[second];
39 | arr[second] = temp;
40 |
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/Flow Control, Loops & Function/LeapYear.java:
--------------------------------------------------------------------------------
1 |
2 | import java.util.Scanner;
3 |
4 | class Main {
5 |
6 |
7 | // } Driver Code Ends
8 | //User function Template for Java
9 |
10 | public static void utility(int y){
11 | String isLeap = "False";
12 | if(y%4==0 && y%100!=0){
13 | isLeap="True";
14 | }else if(y%400==0){
15 | isLeap="True";
16 | }else{
17 | isLeap="
18 |
19 | //Your code below
20 | //Assign True or False to isLeap
21 |
22 | //Your code above
23 |
24 | //The line below prints the output
25 | System.out.println(isLeap);
26 | }
27 |
28 | //{ Driver Code Starts.
29 |
30 | public static void main(String[] args)
31 | {
32 | Scanner scn = new Scanner(System.in);
33 | int t = scn.nextInt();
34 | while(t-- > 0) {
35 | int y = scn.nextInt();
36 | utility(y);
37 | }
38 | scn.close();
39 | }
40 | }
41 | // } Driver Code Ends
42 |
--------------------------------------------------------------------------------
/Searching/Majority Element.java:
--------------------------------------------------------------------------------
1 | class Solution
2 | {
3 | static int majorityElement(int a[], int size)
4 | {
5 | // your code heren
6 | int ele=a[0];
7 | int freq=0;
8 |
9 | for(int i=0;i=(size/2)+1){
37 | return ele;
38 | }
39 |
40 | else{
41 | return -1;
42 | }
43 |
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Flow Control, Loops & Function/CheckPrime.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | class Main {
4 |
5 |
6 | // } Driver Code Ends
7 | //User function Template for Java
8 |
9 | public static boolean prime(int n){
10 |
11 | //Write your code here
12 | //returns a boolean value
13 | if(n==1){
14 | return false;
15 | }
16 | for(int i=2;i*i<=n;i++){
17 | if(n%i==0){
18 | return false;
19 | }
20 | }
21 |
22 | return true;
23 | }
24 |
25 | //{ Driver Code Starts.
26 |
27 | public static void main(String[] args)
28 | {
29 | Scanner scn = new Scanner(System.in);
30 | int t = scn.nextInt();
31 | while(t-- > 0) {
32 | int n = scn.nextInt();
33 | boolean ans = prime(n);
34 | if(ans)
35 | System.out.println("True");
36 | else
37 | System.out.println("False");
38 | }
39 | scn.close();
40 | }
41 | }
42 | // } Driver Code Ends
43 |
--------------------------------------------------------------------------------
/Flow Control, Loops & Function/Calculator.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | class Main {
4 |
5 |
6 | // } Driver Code Ends
7 | //User function Template for Java
8 |
9 | public static void utility(int a, int b, int operator){
10 |
11 | //write your code here
12 | switch(operator){
13 | case 1:System.out.print(a+b);break;
14 | case 2:System.out.print(a-b);break;
15 | case 3:System.out.print(a*b);break;
16 | default:System.out.println("Invalid Input");break;
17 | }
18 |
19 |
20 | }
21 |
22 | //{ Driver Code Starts.
23 |
24 | public static void main(String[] args)
25 | {
26 | Scanner scn = new Scanner(System.in);
27 | int t = scn.nextInt();
28 | while(t-- > 0) {
29 | int a = scn.nextInt();
30 | int b = scn.nextInt();
31 | int operator = scn.nextInt();
32 | utility(a, b, operator);
33 | System.out.println();
34 | }
35 | scn.close();
36 | }
37 | }
38 | // } Driver Code Ends
39 |
--------------------------------------------------------------------------------
/Introduction, Variables and Operators/13_GP_Term.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 | import java.util.*;
3 | class Mathematics {
4 | public static void main (String[] args) {
5 |
6 | //taking input using Scanner class
7 | Scanner sc=new Scanner(System.in);
8 |
9 | //taking total testcases
10 | int T=sc.nextInt();
11 | while(T-->0)
12 | {
13 |
14 | Solution obj=new Solution ();
15 | int A,B;
16 |
17 | //taking A and B
18 | A=sc.nextInt();
19 | B=sc.nextInt();
20 | int N;
21 |
22 | //taking N
23 | N=sc.nextInt();
24 |
25 | //calling method termOfGP() of class GP
26 | System.out.println((int)Math.floor(obj.termOfGP(A,B,N)));
27 |
28 | }
29 |
30 | }
31 | }
32 |
33 | // } Driver Code Ends
34 |
35 |
36 | //User function Template for Java
37 |
38 | class Solution
39 | {
40 |
41 | public double termOfGP(int A,int B,int N)
42 | {
43 | //Your code here
44 | // int N=A+B;
45 | return (A*Math.pow((double)B/A,N-1));
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/Searching/Search in Rotated Sorted Array.java:
--------------------------------------------------------------------------------
1 | class Solution
2 | {
3 | public int search(int[] nums, int target)
4 | {
5 | int left = 0, right = nums.length - 1, mid;
6 | while (left <= right)
7 | {
8 | mid = left + (right - left) / 2;
9 | if (nums[mid] == target)
10 | return mid;
11 | // condition for left side is sort
12 | if (nums[left] <= nums[mid])
13 | {
14 | if (target >= nums[left] && target <= nums[mid])
15 | {
16 | right = mid - 1;
17 | }
18 | else
19 | {
20 | left = mid + 1;
21 | }
22 | }
23 | else
24 | {
25 | if (target >= nums[mid] && target <= nums[right])
26 | {
27 | left = mid + 1;
28 | }
29 | else
30 | {
31 | right = mid - 1;
32 | }
33 | }
34 | }
35 | return -1;
36 | }
37 | }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 savarapu manohar joshi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Backtracking Problems/NQueens.java:
--------------------------------------------------------------------------------
1 | // Java code to for n Queen placement
2 | class NQueens
3 | {
4 |
5 | static void breakLine()
6 | {
7 | System.out.print("\n---------------------------------\n");
8 | }
9 | static int MAX = 10;
10 |
11 | static int arr[] = new int[MAX], no;
12 |
13 | // Function to check queens placement
14 | static void nQueens(int k, int n)
15 | {
16 |
17 | for (int i = 1; i <= n; i++)
18 | {
19 | if (canPlace(k, i))
20 | {
21 | arr[k] = i;
22 | if (k == n)
23 | {
24 | display(n);
25 | }
26 | else
27 | {
28 | nQueens(k + 1, n);
29 | }
30 | }
31 | }
32 | }
33 |
34 | // Helper Function to check if queen can be placed
35 | static boolean canPlace(int k, int i)
36 | {
37 | for (int j = 1; j <= k - 1; j++)
38 | {
39 | if (arr[j] == i ||
40 | (Math.abs(arr[j] - i) == Math.abs(j - k)))
41 | {
42 | return false;
43 | }
44 | }
45 | return true;
46 | }
47 |
48 | // Function to display placed queen
49 | static void display(int n)
50 | {
51 | breakLine();
52 | System.out.print("Arrangement No. " + ++no);
53 | breakLine();
54 |
55 | for (int i = 1; i <= n; i++)
56 | {
57 | for (int j = 1; j <= n; j++)
58 | {
59 | if (arr[i] != j)
60 | {
61 | System.out.print("\t_");
62 | }
63 | else
64 | {
65 | System.out.print("\tQ");
66 | }
67 | }
68 | System.out.println("");
69 | }
70 |
71 | breakLine();
72 | }
73 |
74 | // Driver Code
75 | public static void main(String[] args)
76 | {
77 | int n = 4;
78 | nQueens(1, n);
79 | }
80 | }
81 |
82 | // This code is contributed by 29AjayKumar
83 |
--------------------------------------------------------------------------------
/print all palindrome of string.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 |
5 | bool checkPalindrome(string str)
6 | {
7 | int len = str.length();
8 | len--;
9 | for (int i=0; i > partitions)
19 | {
20 | for (int i = 0; i < partitions.size(); ++i)
21 | {
22 | for(int j = 0; j < partitions[i].size(); ++j)
23 | cout << partitions[i][j] << " ";
24 | cout << endl;
25 | }
26 | return;
27 | }
28 |
29 |
30 | void addStrings(vector > &v, string &s,
31 | vector &temp, int index)
32 | {
33 | int len = s.length();
34 | string str;
35 | vector current = temp;
36 | if (index == 0)
37 | temp.clear();
38 | for (int i = index; i < len; ++i)
39 | {
40 | str = str + s[i];
41 | if (checkPalindrome(str))
42 | {
43 | temp.push_back(str);
44 | if (i+1 < len)
45 | addStrings(v,s,temp,i+1);
46 | else
47 | v.push_back(temp);
48 | temp = current;
49 | }
50 | }
51 | return;
52 | }
53 |
54 |
55 | void partition(string s, vector >&v)
56 | {
57 | vector temp;
58 | addStrings(v, s, temp, 0);
59 | printSolution(v);
60 | return;
61 | }
62 |
63 |
64 | int main()
65 | {
66 | string s = "geeks";
67 | vector > partitions;
68 | partition(s, partitions);
69 | return 0;
70 | }
71 |
--------------------------------------------------------------------------------
/IBM-SE-Intern/Even_odd.java:
--------------------------------------------------------------------------------
1 | //{ Driver Code Starts
2 | // Initial Template for Java
3 |
4 | import java.io.*;
5 | import java.util.*;
6 |
7 | // Position this line where user code will be pasted.
8 |
9 | class GFG {
10 |
11 | // Driver code
12 | public static void main(String[] args) {
13 |
14 | // Taking input using scanner class
15 | Scanner sc = new Scanner(System.in);
16 |
17 | // taking count of testcases
18 | int testcase = sc.nextInt();
19 |
20 | while (testcase-- > 0) {
21 |
22 | // taking size of arary
23 | int sizeof_array = sc.nextInt();
24 |
25 | // creating an array
26 | int a[] = new int[sizeof_array];
27 |
28 | // inserting elements in the array
29 | for (int i = 0; i < sizeof_array; i++) {
30 | a[i] = sc.nextInt();
31 | }
32 |
33 | // creating an object of class Geeks
34 | Geeks obj = new Geeks();
35 |
36 | // calling countOddEven() method
37 | // of class Geeks
38 | obj.countOddEven(a, sizeof_array);
39 | System.out.println();
40 | }
41 | }
42 | }
43 |
44 | // } Driver Code Ends
45 |
46 |
47 | // User function Template for Java
48 |
49 | /*Class Geeks with countOddEven() as its member function
50 | * a : input array
51 | * n : size of array
52 | */
53 | class Geeks {
54 | static void countOddEven(int a[], int n) {
55 |
56 | // Your code herent
57 | int odd=0;
58 | int even=0;
59 | for(int i=0;i Array to be sorted,
40 | low --> Starting index,
41 | high --> Ending index */
42 | void sort(int arr[], int low, int high)
43 | {
44 | if (low < high)
45 | {
46 | /* pi is partitioning index, arr[pi] is
47 | now at right place */
48 | int pi = partition(arr, low, high);
49 |
50 | // Recursively sort elements before
51 | // partition and after partition
52 | sort(arr, low, pi-1);
53 | sort(arr, pi+1, high);
54 | }
55 | }
56 |
57 | /* A utility function to print array of size n */
58 | static void printArray(int arr[])
59 | {
60 | int n = arr.length;
61 | for (int i=0; i visit = new HashSet();
48 |
49 | Queue q = new LinkedList<>();
50 | String temp;
51 | boolean level = false;
52 |
53 | q.add(str);
54 | visit.add(str);
55 | while (!q.isEmpty())
56 | {
57 | str = q.peek(); q.remove();
58 | if (isValidString(str))
59 | {
60 | System.out.println(str);
61 | level = true;
62 | }
63 | if (level)
64 | continue;
65 | for (int i = 0; i < str.length(); i++)
66 | {
67 | if (!isParenthesis(str.charAt(i)))
68 | continue;
69 |
70 | temp = str.substring(0, i) + str.substring(i + 1);
71 | if (!visit.contains(temp))
72 | {
73 | q.add(temp);
74 | visit.add(temp);
75 | }
76 | }
77 | }
78 | }
79 |
80 | public static void main(String[] args)
81 | {
82 | String expression = "()())()";
83 | removeInvalidParenthesis(expression);
84 |
85 | expression = "()v)";
86 | removeInvalidParenthesis(expression);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/N queen problem .cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | vector > result;
5 |
6 |
7 | bool isSafe(vector > board,
8 | int row, int col)
9 | {
10 | int i, j;
11 | int N = board.size();
12 |
13 |
14 | if (board[row][i])
15 | return false;
16 |
17 |
18 | for (i = row, j = col; i >= 0 && j >= 0; i--, j--)
19 | if (board[i][j])
20 | return false;
21 |
22 | for (i = row, j = col; j >= 0 && i < N; i++, j--)
23 | if (board[i][j])
24 | return false;
25 |
26 | return true;
27 | }
28 |
29 |
30 | bool solveNQUtil(vector >& board, int col)
31 | {
32 |
33 | int N = board.size();
34 | if (col == N) {
35 | vector v;
36 | for (int i = 0; i < N; i++) {
37 | for (int j = 0; j < N; j++) {
38 | if (board[i][j] == 1)
39 | v.push_back(j + 1);
40 | }
41 | }
42 | result.push_back(v);
43 | return true;
44 | }
45 |
46 |
47 | bool res = false;
48 | for (int i = 0; i < N; i++) {
49 |
50 | if (isSafe(board, i, col)) {
51 | board[i][col] = 1;
52 |
53 |
54 | res = solveNQUtil(board, col + 1) || res;
55 |
56 | board[i][col] = 0; // BACKTRACK
57 | }
58 | }
59 |
60 |
61 | return res;
62 | }
63 |
64 |
65 |
66 | vector > nQueen(int n)
67 | {
68 | result.clear();
69 | vector > board(n, vector(n, 0));
70 |
71 | if (solveNQUtil(board, 0) == false) {
72 | return {};
73 | }
74 |
75 | sort(result.begin(), result.end());
76 | return result;
77 | }
78 |
79 | // Driver Code
80 | int main()
81 | {
82 | int n = 4;
83 | vector > v = nQueen(n);
84 |
85 | for (auto ar : v) {
86 | cout << "[";
87 | for (auto it : ar)
88 | cout << it << " ";
89 | cout << "]";
90 | }
91 |
92 | return 0;
93 | }
94 |
--------------------------------------------------------------------------------
/Singlylinkedlist.java:
--------------------------------------------------------------------------------
1 | // Java Program to Create a Singly Linked List
2 | // of n Nodes and Count the Number of Nodes
3 | import java.io.*;
4 | import java.util.*;
5 |
6 | public class LinkedListCreation {
7 |
8 | class Node {
9 | int data;
10 | Node next;
11 |
12 | // constructor to create new node
13 | Node(int data)
14 | {
15 | this.data = data;
16 | this.next = null;
17 | }
18 | }
19 |
20 | // Initially both head and tail are not
21 | // pointing to any other node
22 | Node head = null;
23 | Node tail = null;
24 |
25 | // method to add newNode in Linked List
26 | void addNode(int data)
27 | {
28 |
29 | Node newNode = new Node(data);
30 |
31 | // Checks if the list is empty
32 | if (head == null) {
33 | // If list is empty, both head and
34 | // tail will point to new node
35 | head = newNode;
36 | tail = newNode;
37 | }
38 | else {
39 |
40 | tail.next = newNode;
41 | // storing newnode in tail
42 | tail = newNode;
43 | }
44 | }
45 | // display linked list
46 | void displayNodes()
47 | {
48 |
49 | Node current = head;
50 | if (head == null) {
51 | System.out.println("Empty");
52 | return;
53 | }
54 | System.out.println("Nodes : ");
55 | while (current != null) {
56 |
57 | System.out.print(current.data + " ");
58 | current = current.next;
59 | }
60 | System.out.println();
61 | }
62 |
63 | // method to count nodes
64 | int countNodes()
65 | {
66 | // Initially zero
67 | int count = 0;
68 |
69 | Node currentNode = head;
70 | // iterate until all the nodes are present
71 | while (currentNode != null) {
72 |
73 | count++;
74 | currentNode = currentNode.next;
75 | }
76 | // return the count
77 | return count;
78 | }
79 |
80 | public static void main(String[] args)
81 | {
82 |
83 | LinkedListCreation L1 = new LinkedListCreation();
84 |
85 | L1.addNode(1);
86 | L1.addNode(2);
87 | L1.addNode(3);
88 | L1.addNode(4);
89 |
90 | // Displays the nodes present in the list
91 | L1.displayNodes();
92 |
93 | // Counts the nodes present in the given list
94 | System.out.println("Total Nodes: "
95 | + L1.countNodes());
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/Starting.txt:
--------------------------------------------------------------------------------
1 | Java is currently the most used programming language worldwide.
2 | The biggest tech giants such as Amazon, Google, TCS, Wipro, etc., have a huge percentage of code in Java.
3 |
4 | Java is power-packed with ample of features. Here are some of the most important features of Java Programming Language:
5 | Simple - Java was designed for professional developers to learn and use easily . If you are aware of basic programming principles, then Java is not a hard nut to crack.
6 | Secure - Java achieves security by confining Java Programs to Java Execution Environment and not allowing Java programs to access other parts of the computer system.
7 | Portable - Portable code must run on a variety of operating systems, CPU’s, and browsers. When a Java program is compiled, a Bytecode is generated, this bytecode can be executed on any platform using JVM ( Java Virtual Machine ). We will discuss JVM details in the latter part of the tutorial.
8 | Object-Oriented - Java provides a clean, usable, and pragmatic approach to objects. It was designed on the principle that “Everything under the sun is an Object.”
9 | Robust -The robustness of the program is the reliable execution on a variety of systems. To better understand this, consider one of the main reasons for program failure is memory management. In C/C++, a programmer must manually allocate and free dynamic memory. There are cases where programmers forgot to free up the dynamic memory which may cause program failure. Java virtually solves this problem as unused objects are garbage collected automatically.
10 | Architecture Neutral - The central issue for Java Designers was that of code longevity and portability. One of the main problems for programmers was that there was no guarantee that the program running perfectly fine today will run tomorrow because of the system upgrades, processor upgrades, or changes in core system resources. Java Designers made several hard decisions and designed the Java Virtual Machine to solve this problem. Their goal was “write once, run anywhere, any time, forever“.
11 | Distributed - Java is designed for distributed environment because it handles TCP/IP protocol. It is very much useful in building large scale distributed computing based applications. Java also supports Remote Method Invocation. This feature enables a program to invoke methods across a network.
12 | Dynamic - Java programs have run time meta information to verify and resolve accesses of the objects at runtime. This makes it possible to dynamically link code in a safe and secure environment. It also gives us the feature to update small fragments of bytecode, dynamically updated on a running system.
13 |
--------------------------------------------------------------------------------
/ui/style.css:
--------------------------------------------------------------------------------
1 | .parent-div {
2 | width: 1450px;
3 | height: 2208px;
4 | overflow: hidden;
5 | margin: 0px;
6 | padding: 0px;
7 | box-sizing: border-box;
8 | }
9 | .FRAME-946-2 {
10 | transform: rotate(0deg);
11 | position: relative;
12 | width: 1450px;
13 | height: 2208px;
14 | left: 0px;
15 | top: 0px;
16 | opacity: 1;
17 | overflow: hidden;
18 | background: rgba(255, 252, 247, 1);
19 | }
20 | .GROUP-949-540 {
21 | position: absolute;
22 | width: 1386px;
23 | height: 742px;
24 | left: 27px;
25 | top: 0px;
26 | transform: rotate(0deg);
27 | z-index: 2;
28 | opacity: 1;
29 | }
30 | .GROUP-948-308 {
31 | position: absolute;
32 | width: 1268.269287109375px;
33 | height: 363.99664306640625px;
34 | left: 110px;
35 | top: 209px;
36 | transform: rotate(0deg);
37 | z-index: 3;
38 | opacity: 1;
39 | }
40 | .GROUP-946-4 {
41 | position: absolute;
42 | width: 546px;
43 | height: 78.9299545288086px;
44 | left: 110px;
45 | top: 378px;
46 | transform: rotate(0deg);
47 | z-index: 3;
48 | opacity: 1;
49 | }
50 | .GROUP-946-5 {
51 | position: absolute;
52 | width: 546px;
53 | height: 78.9299545288086px;
54 | left: 110px;
55 | top: 378px;
56 | transform: rotate(0deg);
57 | z-index: 3;
58 | opacity: 1;
59 | }
60 | .RECTANGLE-946-6 {
61 | position: absolute;
62 | left: 110px;
63 | top: 378px;
64 | transform: rotate(0deg);
65 | transform-origin: center !important;
66 | background: rgba(255, 255, 255, 1);
67 |
68 | border-radius: 19px;
69 | border-top-left-radius: 19px;
70 | border-top-right-radius: 19px;
71 | border-bottom-left-radius: 19px;
72 | border-bottom-right-radius: 19px;
73 |
74 | width: 546px;
75 | height: 78.9299545288086px;
76 | opacity: 1;
77 | }
78 | .FRAME-946-7 {
79 | transform: rotate(0deg);
80 | position: absolute;
81 | width: 31.734722137451172px;
82 | height: 31.734722137451172px;
83 | left: 132.78392601013184px;
84 | top: 402.41122817993164px;
85 | opacity: 1;
86 | overflow: hidden;
87 | background: transparent;
88 | }
89 | .FRAME-946-8 {
90 | transform: rotate(0deg);
91 | position: absolute;
92 | width: 30px;
93 | height: 30px;
94 | left: 0.216064453125px;
95 | top: -0.4111328125px;
96 | opacity: 1;
97 | overflow: hidden;
98 | background: transparent;
99 | }
100 | .GROUP-946-15 {
101 | position: absolute;
102 | width: 189.59463500976562px;
103 | height: 78.9299545288086px;
104 | left: 466.4053649902344px;
105 | top: 378px;
106 | transform: rotate(0deg);
107 | z-index: 4;
108 | opacity: 1;
109 | }
110 | .RECTANGLE-946-16 {
111 | position: absolute;
112 | left: 466.4053649902344px;
113 | top: 378px;
114 | transform: rotate(0deg);
115 | transform-origin: center !important;
116 | background: rgba(24, 70, 85, 1);
117 |
118 | border-top-right-radius: 19px;
119 | border-bottom-right-radius: 19px;
120 |
121 | width: 189.59463500976562px;
122 | height: 78.9299545288086px;
123 | opacity: 1;
124 | }
125 | .FRAME-946-36 {
126 | transform: rotate(0deg);
127 | position: absolute;
128 | width: 331px;
129 | height: 25px;
130 | left: 123px;
131 | top: 477px;
132 | opacity: 1;
133 | }
134 | .GROUP-946-41 {
135 | position: absolute;
136 | width: 609.9703979492188px;
137 | height: 363.99664306640625px;
138 | left: 768.298828125px;
139 | top: 209px;
140 | transform: rotate(0deg);
141 | z-index: 6;
142 | opacity: 1;
143 | }
144 | .GROUP-946-42 {
145 | position: absolute;
146 | width: 609.9703979492188px;
147 | height: 363.99664306640625px;
148 | left: 768.298828125px;
149 | top: 209px;
150 | transform: rotate(0deg);
151 | z-index: 6;
152 | opacity: 1;
153 | }
154 | .FRAME-946-251 {
155 | transform: rotate(0deg);
156 | position: absolute;
157 | width: 612px;
158 | height: 29px;
159 | left: 770px;
160 | top: 890px;
161 | opacity: 1;
162 | }
163 | .GROUP-946-257 {
164 | position: absolute;
165 | width: 1385.53173828125px;
166 | height: 469px;
167 | left: 27px;
168 | top: 1352px;
169 | transform: rotate(0deg);
170 | z-index: 9;
171 | opacity: 1;
172 | }
173 | .GROUP-946-258 {
174 | position: absolute;
175 | width: 431.53167724609375px;
176 | height: 469px;
177 | left: 27px;
178 | top: 1352px;
179 | transform: rotate(0deg);
180 | z-index: 9;
181 | opacity: 1;
182 | }
183 | .RECTANGLE-946-259 {
184 | position: absolute;
185 | left: 27px;
186 | top: 1352px;
187 | transform: rotate(0deg);
188 | transform-origin: center !important;
189 | background-image: linear-gradient(
190 | 146.32deg,
191 | rgba(248, 246, 246, 0.1) 0%,
192 | rgba(249, 247, 247, 0.4) 100%
193 | );
194 | border-radius: 41px;
195 | border-top-left-radius: 41px;
196 | border-top-right-radius: 41px;
197 | border-bottom-left-radius: 41px;
198 | border-bottom-right-radius: 41px;
199 |
200 | backdrop-filter: blur(20px);
201 | box-shadow: 0px 2px 20px -1px rgba(0, 0, 0, 0.25);
202 |
203 | width: 431.53167724609375px;
204 | height: 469px;
205 | opacity: 1;
206 | }
207 | .FRAME-946-262 {
208 | transform: rotate(0deg);
209 | position: absolute;
210 | width: 395.3553771972656px;
211 | height: 18.734159469604492px;
212 | left: 45px;
213 | top: 1678px;
214 | opacity: 1;
215 | }
216 | .GROUP-946-267 {
217 | position: absolute;
218 | width: 431.53167724609375px;
219 | height: 469px;
220 | left: 504px;
221 | top: 1352px;
222 | transform: rotate(0deg);
223 | z-index: 10;
224 | opacity: 1;
225 | }
226 | .RECTANGLE-946-268 {
227 | position: absolute;
228 | left: 504px;
229 | top: 1352px;
230 | transform: rotate(0deg);
231 | transform-origin: center !important;
232 | background-image: linear-gradient(
233 | 146.32deg,
234 | rgba(248, 246, 246, 0.1) 0%,
235 | rgba(249, 247, 247, 0.4) 100%
236 | );
237 | border-radius: 41px;
238 | border-top-left-radius: 41px;
239 | border-top-right-radius: 41px;
240 | border-bottom-left-radius: 41px;
241 | border-bottom-right-radius: 41px;
242 |
243 | backdrop-filter: blur(20px);
244 | box-shadow: 0px 2px 20px -1px rgba(0, 0, 0, 0.25);
245 |
246 | width: 431.53167724609375px;
247 | height: 469px;
248 | opacity: 1;
249 | }
250 | .FRAME-946-270 {
251 | transform: rotate(0deg);
252 | position: absolute;
253 | width: 395.3553771972656px;
254 | height: 18.734159469604492px;
255 | left: 522px;
256 | top: 1678px;
257 | opacity: 1;
258 | }
259 | .GROUP-946-275 {
260 | position: absolute;
261 | width: 431.53167724609375px;
262 | height: 469px;
263 | left: 981px;
264 | top: 1352px;
265 | transform: rotate(0deg);
266 | z-index: 11;
267 | opacity: 1;
268 | }
269 | .GROUP-946-276 {
270 | position: absolute;
271 | width: 431.53167724609375px;
272 | height: 469px;
273 | left: 981px;
274 | top: 1352px;
275 | transform: rotate(0deg);
276 | z-index: 11;
277 | opacity: 1;
278 | }
279 | .RECTANGLE-946-277 {
280 | position: absolute;
281 | left: 981px;
282 | top: 1352px;
283 | transform: rotate(0deg);
284 | transform-origin: center !important;
285 | background-image: linear-gradient(
286 | 146.32deg,
287 | rgba(248, 246, 246, 0.1) 0%,
288 | rgba(249, 247, 247, 0.4) 100%
289 | );
290 | border-radius: 41px;
291 | border-top-left-radius: 41px;
292 | border-top-right-radius: 41px;
293 | border-bottom-left-radius: 41px;
294 | border-bottom-right-radius: 41px;
295 |
296 | backdrop-filter: blur(20px);
297 | box-shadow: 0px 2px 20px -1px rgba(0, 0, 0, 0.25);
298 |
299 | width: 431.53167724609375px;
300 | height: 469px;
301 | opacity: 1;
302 | }
303 | .FRAME-946-280 {
304 | transform: rotate(0deg);
305 | position: absolute;
306 | width: 395.3553771972656px;
307 | height: 18.734159469604492px;
308 | left: 999px;
309 | top: 1678px;
310 | opacity: 1;
311 | }
312 | .GROUP-948-286 {
313 | position: absolute;
314 | width: 1342px;
315 | height: 66px;
316 | left: 54px;
317 | top: 27px;
318 | transform: rotate(0deg);
319 | z-index: 11;
320 | opacity: 1;
321 | }
322 | .GROUP-946-18 {
323 | position: absolute;
324 | width: 230px;
325 | height: 66px;
326 | left: 54px;
327 | top: 27px;
328 | transform: rotate(0deg);
329 | z-index: 11;
330 | opacity: 1;
331 | }
332 | .FRAME-946-20 {
333 | transform: rotate(0deg);
334 | position: absolute;
335 | width: 179px;
336 | height: 66px;
337 | left: 105px;
338 | top: 27px;
339 | opacity: 1;
340 | }
341 | .FRAME-946-22 {
342 | transform: rotate(0deg);
343 | position: absolute;
344 | width: 96px;
345 | height: 49px;
346 | left: 292px;
347 | top: 37px;
348 | opacity: 1;
349 | }
350 | .FRAME-946-25 {
351 | transform: rotate(0deg);
352 | position: absolute;
353 | width: 245px;
354 | height: 49px;
355 | left: 901px;
356 | top: 36px;
357 | opacity: 1;
358 | }
359 | .FRAME-962-790 {
360 | transform: rotate(0deg);
361 | position: absolute;
362 | width: 108.694580078125px;
363 | height: 26px;
364 | left: 10px;
365 | top: 11.5px;
366 | opacity: 1;
367 | overflow: hidden;
368 | }
369 | .GROUP-946-29 {
370 | position: absolute;
371 | width: 78.33334350585938px;
372 | height: 26px;
373 | left: 156.66665649414062px;
374 | top: 11.5px;
375 | transform: rotate(0deg);
376 | z-index: 2;
377 | opacity: 1;
378 | }
379 | .GROUP-946-32 {
380 | position: absolute;
381 | width: 223px;
382 | height: 49px;
383 | left: 1173px;
384 | top: 36px;
385 | transform: rotate(0deg);
386 | z-index: 14;
387 | opacity: 1;
388 | }
389 | .RECTANGLE-946-33 {
390 | position: absolute;
391 | left: 1173px;
392 | top: 36px;
393 | transform: rotate(0deg);
394 | transform-origin: center !important;
395 | background: rgba(24, 70, 85, 1);
396 |
397 | border-radius: 23.5px;
398 | border-top-left-radius: 23.5px;
399 | border-top-right-radius: 23.5px;
400 | border-bottom-left-radius: 23.5px;
401 | border-bottom-right-radius: 23.5px;
402 |
403 | filter: drop-shadow(2px 3px 1px rgba(0, 0, 0, 0.25));
404 |
405 | width: 223px;
406 | height: 49px;
407 | opacity: 1;
408 | }
409 |
--------------------------------------------------------------------------------