Current streak:
37 days
Longest streak:
37 days
Less
More
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;
}
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();
}
}
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;
}
}
#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;
}
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); } } }
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] + " "); } }
}
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);
}
}
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] + " "); } }
}