Update appNew update is available. Click here to update.
About
Pre-final year student at Indira Gandhi Delhi Technical University For Women
Indira Gandhi Delhi Technical University for Women 2025
My Stats
EXP gained
yellow-spark
3228
Level
5 (Champion)
Community stats
Discussions
0
Upvotes
3
Know more
153
Total problems solved
127
Easy
24
Moderate
2
Hard
0
Ninja
Jan Jan Feb Feb Mar Mar Apr Apr May May Jun Jun Jul Jul Aug Aug Sep Sep Oct Oct Nov Nov Dec Dec

Current streak:

0 days

Longest streak:

5 days

Less

More

Discussions
EASY JAVA SOLUTION | PLEASE UPVOTE
Interview problems
public static int maximumMeetings(int []start, int []end) {
        // Write your code here.
        int n = start.length;
        int m[][] = new int[n][2];
        for(int i=0;i<n;i++){
            m[i][0] = start[i];
            m[i][1] = end[i];
        }
        Arrays.sort(m,(a,b) -> a[1] - b[1]);
        int c = 1;
        int e = m[0][1];
        for(int i=1;i<m.length;i++){
            if(m[i][0] > e){
                e = m[i][1];
                c++;
            }
        }
        return c;
    }
profile
sakshhhhi
Published On 12-Sep-2023
83 views
1 replies
0 upvotes
Java HashMap Solution
Interview problems
 public static int maximumMeetings(int []start, int []end) {
        int n = start.length;
        // Write your code here.
         HashMap<Integer,Integer> map = new HashMap<>();
        for(int i =0; i<n;i++){
            if(map.containsKey(end[i])){
                if(start[i]>map.get(end[i])){
                    map.put(end[i],start[i]);
                }
            }else{
                map.put(end[i],start[i]);
            }
            
        }
        Arrays.sort(end);
        int count = 0;
        
        int eT  = -1;
        for(int i=0;i<n;i++){
            if(eT< map.get(end[i])){
                count++;
                eT = end[i];
            }
        }
        return count;
    }
profile
sakshhhhi
Published On 12-Sep-2023
78 views
0 replies
0 upvotes
Java Easy Solution
Interview problems
public class Solution {
    static ArrayList<Integer> res = new ArrayList<>();
    public static ArrayList<Integer> subsetSum(int num[]) {
        // Write your code here..
        sumFinder(num,0,0);
        Collections.sort(res);
        return res;

    }
    public static void sumFinder(int num[],int idx,int sum){
        if(idx==num.length){
            res.add(sum);
        }
        else{
            sumFinder(num, idx+1, sum+num[idx]);
            sumFinder(num, idx+1, sum);
        }
    }

}
profile
sakshhhhi
Published On 06-Sep-2023
38 views
0 replies
0 upvotes
Easy Java Solution| O(n) | O(1)
Interview problems

import java.util.* ; import java.io.*;  /************************************************************

   Following is the TreeNode class structure

   class TreeNode<T>    {       public:        T data;        TreeNode<T> left;        TreeNode<T> right;

       TreeNode(T data)        {            this.data = data;            left = null;            right = null;        }    };

************************************************************/

public class Solution {

   public  static int findCeil(TreeNode<Integer> node, int x) {        int res =-1;

       // Write your code here        while(node!=null){            if(node.data==x){                res = node.data;                return res;            }            else if(node.data<x){                node=node.right;            }            else{                res = node.data;                node=node.left;            }        }        return res;

   } }  

profile
sakshhhhi
Published On 05-Sep-2023
98 views
0 replies
0 upvotes
Java easy Solution
Interview problems

 

    public class Solution {




    public static int floorInBST(TreeNode<Integer> root, int X) {

        //    Write your code here.

        TreeNode<Integer>res=null;        

        while(root!=null){  

            if(root.data==X)           

                return root.data;            

            else if(root.data>X)           

                root=root.left;            

            else{                

                res=root;                

                root=root.right;            

                }        

         }

        return res.data;  
profile
sakshhhhi
Published On 05-Sep-2023
82 views
0 replies
0 upvotes
Easy Java Solution
Interview problems

public class Solution {

    private static long minVal =Long.MIN_VALUE;

 

    public static boolean isBST(BinaryTreeNode<Integer> root) {

 

        /* Your class should be named Solution

         * Don't write main().

         * Don't read input, it is passed as function argument.

         * Return output and don't print it.

         * Taking input and printing output is handled automatically.

        */

        if(root==null){

            return true;

        }

        if(!isBST(root.left)){

            return false;

        }

        if(minVal>=root.data){

            return false;

        }

        minVal =root.data;

        if(!isBST(root.right)){

            return false;

        }

        return true;

 

    }

 

}

profile
sakshhhhi
Published On 05-Sep-2023
56 views
0 replies
0 upvotes
Java Solution| Merge Sort Approach : Time Complexity : O(nlog(n))
Interview problems

public class Solution {

    public static long merge(long arr[],int begin ,int mid, int end){

        int i =begin,j=mid,k=0;

        long count =0;

        long temp[] = new long[(end-begin+1)];

 

        while(i<mid && j<=end){

            if(arr[i]<=arr[j]){

                temp[k]=arr[i];

                ++k;

                ++i;

            }

            else{

                temp[k]=arr[j];

                count+=(mid-i);

                ++k;

                ++j;

            }

        }

        while(i<mid){

            temp[k]=arr[i];

                ++k;

                ++i;

        }

        while(j<=end){

            temp[k]=arr[j];

                ++k;

                ++j;

        }

        for(i=begin,k=0;i<=end;i++,k++){

            arr[i]=temp[k];

        }

        return count;

    }

    

    public static long mergeSort(long arr[], int begin , int end){

        long count=0;

        if(end>begin){

        int mid =(begin+end)/2;

        count+=mergeSort(arr, begin, mid);

        count+=mergeSort(arr, mid+1, end);

        count+=merge(arr,begin,mid+1,end);

        }

        return count;

    }

    public static long getInversions(long arr[], int n) {

        // Write your code here.

        return mergeSort(arr,0,n-1);

    }

profile
sakshhhhi
Published On 26-Aug-2023
171 views
0 replies
2 upvotes
Java Solution
Interview problems

import java.util.* ; import java.io.*;  public class Deque  {    // Initialize your data structure.    int arr[];    int front;    int rear;    int n;    public Deque(int size)     {        n=size;        arr = new int[n];        front=rear=-1;        

   }

   // Pushes 'X' in the front of the deque. Returns true if it gets pushed into the deque, and false otherwise.    public boolean pushFront(int x)     {        if(isFull()==true){            return false;        }        else{            if(front==-1){                front=0;                rear=0;            }            else if(front==0){                front=n-1;            }            else{                --front;            }            arr[front]=x;            return true;        }    }

   // Pushes 'X' in the back of the deque. Returns true if it gets pushed into the deque, and false otherwise.    public boolean pushRear(int x)     {        if(isFull()==true){            return false;        }        else{            if(front==-1){                front=0;                rear=0;            }            else if(rear==n-1){                rear=0;            }            else{                ++rear;            }            arr[rear]=x;            return true;        }    }

   // Pops an element from the front of the deque. Returns -1 if the deque is empty, otherwise returns the popped element.    public int popFront()     {        if(isEmpty()==true){            return -1;        }        else{            int val=arr[front];            if(front==rear){                front=-1;                rear=-1;            }            else if(front==n-1){                front=0;            }            else{                ++front;            }            return val;        }    }

   // Pops an element from the back of the deque. Returns -1 if the deque is empty, otherwise returns the popped element.    public int popRear()     {       if(isEmpty()==true){           return -1;       }       else{           int val=arr[rear];           if(front==rear){               front=-1;               rear=-1;           }           else if(rear==0){               rear=n-1;           }           else{               rear--;           }           return val;       }    }

   // Returns the first element of the deque. If the deque is empty, it returns -1.    public int getFront()     {        if(isEmpty()==true){            return -1;        }        else{            return arr[front];        }    }

   // Returns the last element of the deque. If the deque is empty, it returns -1.    public int getRear()     {        if(isEmpty()==true){            return -1;        }        else{            return arr[rear];        }    }

   // Returns true if the deque is empty. Otherwise returns false.    public boolean isEmpty()     {        return front==-1;    }

   // Returns true if the deque is full. Otherwise returns false.    public boolean isFull()     {        return (front==0&& rear==arr.length-1)||(front==rear+1);    } }  

profile
sakshhhhi
Published On 09-Jul-2023
39 views
0 replies
0 upvotes
Java Solution
Interview problems

public static boolean isStringPalindrome(String input) {

        if(input.length()<=1){

            return true;

        }

        if(input.charAt(0)==input.charAt(input.length()-1)){

            return isStringPalindrome(input.substring(1, input.length()-1));

        }

        else{

            return false;

        }

 

    }

profile
sakshhhhi
Published On 15-Jun-2023
96 views
0 replies
1 upvotes
Java Solution using Recursion
Interview problems

public static int countZerosRec(int input){

        if(input<10){

            if(input==0){

                return 1;

            }

            else{

                return 0;

            }

        }

        int smallAns=countZerosRec(input/10);

        if(input%10==0){

            smallAns++;

        }

        return smallAns;

    }

profile
sakshhhhi
Published On 15-Jun-2023
75 views
0 replies
0 upvotes