Update appNew update is available. Click here to update.
About
I am presently pursing computer science engineering in Amritsar group of colleges (Punjab technical University Punjab(𝐈𝐊𝐆𝐏𝐓𝐔 𝐊𝐀𝐏𝐔𝐑𝐓𝐇𝐀𝐋𝐀).My hobbies are to organize things well and lear...
Tata Consultancy Services (TCS) - SDE - Intern
ACET AMRITSAR 2024
Python - Default language
My Stats
EXP gained
yellow-spark
42173
Level
7 (Expert)
Community stats
Discussions
0
Upvotes
0
Know more
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
1148
Total problems solved
991
Easy
112
Moderate
37
Hard
8
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:

37 days

Longest streak:

37 days

Less

More

Achievements
4
Ronin
Topics
Greedy
Stacks & Queues
+ 2 more
8
Samurai
Topics
Arrays
Strings
Heap
Sorting
+ 4 more
1
Sensei
Topics
SQL
1
Samurai
Guided path
Basics of java
Discussions
C++ solutions
Interview problems
bool comp(vector<int>&a,vector<int>&b){      
   if(a[1]==b[1])     
       return (a[0] < b[0]);    
   return (a[1] < b[1]); 
}
int attendMaxParties(int n, vector<vector<int>> party) {
   // Write your code here.
   vector<int> days(5001,0);
   int ans=0;
   sort(party.begin(),party.end(),comp);
   
   for(int i=0;i<n;i++){
       int start=party[i][0];
       int end=party[i][1];
       
       int pnt=start;
       while(days[pnt]==1 && pnt<=end){
           pnt++;
       }
       if(pnt<=end){ ans++;
       days[pnt]=1;}
   }
   return ans;
}
profile
Rahul_e9ab
Published On 21-Jul-2023
39 views
0 replies
0 upvotes
Java solution
Interview problems
import java.util.*;
    public class Solution {
        public static int furthestBuilding (int ladders, int bricks, ArrayList<Integer> heights) {
            PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
            for (int i = 0; i < heights.size() - 1; i++) {
                if (heights.get(i) > heights.get(i + 1))
                    continue;
                int jump = heights.get(i + 1) - heights.get(i);
                bricks -= jump;
                pq.add(jump);
                if (bricks < 0) {
                    bricks += pq.poll();
                    if (ladders > 0)
                        ladders--;
                    else
                        return i + 1;
                }
            }
            return heights.size();
        }
    }
profile
Rahul_e9ab
Published On 21-Jul-2023
17 views
0 replies
0 upvotes
java
Interview problems

public class Solution {

 

   public static int binarySearch(int[] arr, int x) {

       for(int i=0; i<arr.length; i++){

           if(arr[i] == x){

               return i;

           }

       }

       return -1;

   }

}

profile
Rahul_e9ab
Published On 19-Jan-2023
60 views
0 replies
0 upvotes
JAVA [o(n) time and o(1) space]
Interview problems
import java.util.* ;
import java.io.*; 
import java.util.ArrayList;

public class Solution {

    public static int[] missingAndRepeating(ArrayList<Integer> arr, int n) {
        HashMap<Integer, Boolean> map = new HashMap<>();
        int[] ans = new int[2];
        
        for(int i=0; i<n; i++) {
            if(map.containsKey(arr.get(i)))
                ans[1] = arr.get(i);
            else
                map.put(arr.get(i), true);
        }
        
        for(int i=1; i<=n; i++) {
            if(!map.containsKey(i)) {
                ans[0] = i;
                break;
            }
        }
        
        return ans;
    }
}
profile
Rahul_e9ab
Published On 19-Jan-2023
121 views
1 replies
0 upvotes
O(N)
Interview problems
#include <bits/stdc++.h> 
int maximumProfit(vector<int> &prices){
    // Write your code here.
    if(prices.size()==1) return 0;
    int mini = prices[0];
    int maxi_profit = 0;
    
    for(int i = 1; i<prices.size(); i++){
        mini = min(mini,prices[i]);
        maxi_profit = max(maxi_profit, prices[i]-mini);
    }
    
    return maxi_profit;
    
}
profile
Rahul_e9ab
Published On 19-Jan-2023
60 views
0 replies
0 upvotes
java
Interview problems

import java.util.Arrays;

public class Solution {

 

  public static void sort012(int[] arr){

          Arrays.sort(arr);

  } }  

profile
Rahul_e9ab
Published On 27-Oct-2022
146 views
0 replies
1 upvotes
java
Interview problems

import java.util.Scanner;; class Solution { public static void main(String args[]) {    // Write code here        Scanner s = new Scanner(System.in);        int n = s.nextInt();        int [] arr= new int[n];        for(int i = 0 ; i < n ;i++)        {            arr[i] = s.nextInt();               }        int x = s.nextInt();        int count = 0;        for(int  i= 0 ; i < n ; i++)        {            if (arr[i]  == x)            {                System.out.print(i);                count++;                break;            }                    }        if(count != 1)        {            System.out.print(-1);        }    }       }

profile
Rahul_e9ab
Published On 27-Oct-2022
63 views
0 replies
0 upvotes
java
Interview problems

import java.util.Scanner;

class Solution {

   public static void main(String args[]) {        Scanner sc = new Scanner(System.in);        int n = sc.nextInt(); // number of elements        int arr[] = new int[n];        // Initializing array elements        for (int i = 0; i < n; i++) {            arr[i] = sc.nextInt();        }

       reverseArray(arr, 0, n - 1, n);    }

   // Function to reverse array    static void reverseArray(int arr[], int start, int end, int size) {        while (start < end) {            int temp = arr[start];            arr[start] = arr[end];            arr[end] = temp;            start++;            end--;        }

       for (int i = 0; i < size; i++) {            System.out.print(arr[i] + " ");        }    }

}  

profile
Rahul_e9ab
Published On 27-Oct-2022
50 views
0 replies
0 upvotes
java
Interview problems
import java.util.* ;
import java.io.*; 
import java.util.Scanner;
class Solution {
	
    static int  countWords(String input) {
        // Write your code here
        String str[] = input.split("\\ ");
        return str.length;
    }
    
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        int output = countWords(input);
        System.out.println(output);
		
	}
}
profile
Rahul_e9ab
Published On 27-Oct-2022
62 views
0 replies
0 upvotes
java
Interview problems

import java.util.Scanner;

class Solution {

   public static void main(String args[]) {        Scanner sc = new Scanner(System.in);        int n = sc.nextInt();         int arr[] = new int[n];                for (int i = 0; i < n; i++) {            arr[i] = sc.nextInt();        }

       int k = sc.nextInt(); // No. of times to rotate        rotateArray(arr, n, k);    }

   static void rotateArray(int arr[], int n, int k) {                for (int i = 0; i < k; i++) {            int temp = arr[0];            for (int j = 0; j < n - 1; j++)                arr[j] = arr[j + 1];                arr[n - 1] = temp;        }

              for (int i = 0; i < n; i++) {            System.out.print(arr[i] + " ");        }    }

}  

profile
Rahul_e9ab
Published On 27-Oct-2022
117 views
0 replies
0 upvotes