My Stats
EXP gained
15689
Level
7 (Expert)
Community stats
Discussions
0
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 %
419
Total problems solved
341
Easy
70
Moderate
8
Hard
0
Ninja

Current streak:

0 days

Longest streak:

9 days

Less

More

Achievements
4
Ronin
Topics
Strings
Binary Search
+ 2 more
4
Samurai
Topics
SQL
Arrays
+ 1 more
2
Sensei
Guided path
Fundamentals of Html
+ 1 more
Discussions
help me only 59 test case pass
Interview problems

#include <bits/stdc++.h>

bool compare(vector<int>a,vector<int>b)

{

return a[2]>b[2];

}

vector<int> jobScheduling(vector<vector<int>> &jobs)

{

// Write your code here

sort(jobs.begin(),jobs.end(),compare);

vector<int>output;

int n=jobs.size();

int m=jobs[0].size();

int size=0;

for(int i=0;i<n;i++)

{

if(jobs[i][1]>size)

size=jobs[i][1];

}

int arr[size+1];

for(int i=0;i<=size;i++)

arr[i]=-1;

int countOfJobs=0;

int totalMoney=0;

for(int i=0;i<n;i++)

{

for(int j=jobs[i][1];j>=1;j--)

{

if(arr[j]==-1)

{

countOfJobs++;

totalMoney+=jobs[i][2];

arr[j]=i;

break;

}

}

}

output.push_back(countOfJobs);

output.push_back(totalMoney);

return output;

}

Published On 07-Sep-2023
175 views
1 replies
Best Solution cpp
Interview problems

vector<int> nextGreaterPermutation(vector<int> &arr) {

// Write your code here.

int breakpoint=-1;

int n =arr.size();

for(int i=n-2;i>=0;i--){

if(arr[i]<arr[i+1])

{

breakpoint=i;

break;

}

}

if(breakpoint==-1)

{

int i=0;

int j=n-1;

while(i<=j){

int temp=arr[i];

arr[i]=arr[j];

arr[j]=temp;

i++;

j--;

}

}

else{

for(int i=n-1;i>=0;i--)

{

if(arr[i]>arr[breakpoint]){

swap(arr[i],arr[breakpoint]);

break;

}

}

int i= breakpoint+1;

int j=n-1;

while(i<j){

int temp=arr[i];

arr[i]=arr[j];

arr[j]=temp;

i++;

j--;

}

}

return arr;

}

Published On 29-Aug-2023
47 views
0 replies
Best solution
Interview problems

#include <bits/stdc++.h>

vector<vector<int>> zeroMatrix(vector<vector<int>> &arr, int n, int m) {

// Write your code here.

int ans=1;

for(int i=0;i<n;i++)

{

for(int j=0;j<m;j++)

{

if(arr[i][j]==0)

{

arr[i][0]=0;

if(j==0)

ans=0;

else

arr[0][j]=0;

}

}

}

for(int i=1;i<n;i++)

{

for(int j=1;j<m;j++)

{

if(arr[i][j]!=0)

{

if(arr[0][j]==0 || arr[i][0]==0)

arr[i][j]=0;

}

}

}

if(arr[0][0]==0)

{

for(int i=0;i<m;i++){

arr[0][i]=0;

}

}

if(ans==0)

{

for(int i=0;i<n;i++){

arr[i][0]=0;

}

}

return arr;

}

Published On 27-Aug-2023
119 views
0 replies
Interview problems

#include <bits/stdc++.h>

int atoi(string s) {

// Write your code here.

bool flag = true;

int digit=0;

for(int i=0;i<s.size();i++){

int rem = (int)s[i]-48;

if(rem == -3){

flag = false;

}

else if(rem>=0 && rem<=9){

digit= digit*10+rem;

}

else{continue; }

}

if(flag ==false)

digit=-1*digit;

return digit;

}

Published On 23-Jun-2023
197 views
0 replies
solution
Interview problems

#include <bits/stdc++.h>

vector < int > sortedArray(vector < int > a, vector < int > b) {

set<int>ans;

for (int i = 0; i < a.size(); i++) {

ans.insert(a[i]);

}

for (int i = 0; i < b.size(); i++) {

ans.insert(b[i]);

}

vector<int>ans1;

for(auto x:ans){

ans1.push_back(x);

}

return ans1;

}

Published On 04-Apr-2023
49 views
0 replies
solution
Interview problems

int linearSearch(int n, int num, vector<int> &arr)

{

for(int i=0;i<n;i++){

if(arr[i]==num){return i;}

}

return -1;

}

Published On 04-Apr-2023
94 views
0 replies
solution
Interview problems

#include <bits/stdc++.h>

vector<int> rotateArray(vector<int>& arr, int n) {

int temp = arr[0];

for (int i = 1; i < n; i++) {

arr[i-1]=arr[i];

}

arr[n-1]=temp;

return arr;

}

Published On 04-Apr-2023
122 views
2 replies
solution
Interview problems

#include <bits/stdc++.h>

#include <iostream>

using namespace std;

void Rotate(int arr[], int n, int k) {

k=k%n;

reverse(arr,arr+k);

reverse(arr+k,arr+n);

reverse(arr,arr+n);

for(int i=0;i<n;i++){cout<<arr[i]<<" ";}

}

int main() {

int n;

cin>>n;

int arr[n];

for (int i = 0; i < n; i++) {

cin>>arr[i];

}

int k;

cin>>k;

Rotate(arr,n,k);

return 0;

}

Published On 04-Apr-2023
160 views
0 replies
solution
Interview problems

vector<int> moveZeros(int n, vector<int> a) {

int i=0;

int count=0;

for(int j=0;j<n;j++){

if(a[j]>0){

a[i]=a[j];

i++;

count++;

}

}

for(int i=count;i<n;i++){a[i]=0;}

return a;

}

Published On 04-Apr-2023
45 views
0 replies
solution
Interview problems

#include <bits/stdc++.h>

string leftRotate(string str, int d) {

int n=d%str.size();

if(n==0){return str;}

string s1="",s2="";

for(int i=n;i<str.size();i++){s1.push_back(str[i]);}

for(int i=0;i<n;i++){s2.push_back(str[i]);}

string s3=s1+s2;

return s3;

}

string rightRotate(string str, int d) {

int n=d%str.size();

if(n==0){return str;}

string s1="",s2="";

int n1=str.size()-n;

for(int i=0;i<n1;i++){s1.push_back(str[i]);}

for(int i=n1;i<str.size();i++){s2.push_back(str[i]);}

string s3=s2+s1;

return s3;

}