class Solution {
public:
int candy(vector<int>& ratings) {
int N=ratings.size(), prev=1;
vector<int> cnt(N, 0);
cnt[0] = 1;
for(int i=1;i<N;i++){
if(ratings[i]> ratings[i-1]){
cnt[i] = cnt[i-1]+1;
}
else{
cnt[i]=1;
}
}
for(int i=N-2; i >=0; i--){
if(ratings[i]>ratings[i+1]){
cnt[i] =max(cnt[i], cnt[i+1]+1);
}
}
int sum=accumulate(cnt.begin(), cnt.end(), 0);
return sum;
}
};
Candy Distribution โ
public:
int candy(vector<int>& ratings) {
int N=ratings.size(), prev=1;
vector<int> cnt(N, 0);
cnt[0] = 1;
for(int i=1;i<N;i++){
if(ratings[i]> ratings[i-1]){
cnt[i] = cnt[i-1]+1;
}
else{
cnt[i]=1;
}
}
for(int i=N-2; i >=0; i--){
if(ratings[i]>ratings[i+1]){
cnt[i] =max(cnt[i], cnt[i+1]+1);
}
}
int sum=accumulate(cnt.begin(), cnt.end(), 0);
return sum;
}
};
Candy Distribution โ
โค1
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int solve(int x, int n, vector<int>& a) {
ll ans = 0;
for (int num : a) {
ans += num;
}
if (ans % x != 0) {
return n;
}
ll left = 0, right = n - 1;
while (left < n && a[left] % x == 0) {
left++;
}
while (right >= 0 && a[right] % x == 0) {
right--;
}
ll mm = max(n - left - 1, right);
return mm > 0 ? mm : -1;
}
Crazy Subarray โ
๐1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[] arr = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = scanner.nextInt();
}
int result = findLeftmostIndex(N, arr);
System.out.println(result);
scanner.close();
}
public static int findLeftmostIndex(int N, int[] arr) {
int totalSum = 0;
for (int value : arr) {
totalSum += value;
}
int leftSum = 0;
for (int i = 0; i < N; i++) {
totalSum -= arr[i];
if (leftSum == totalSum) {
return i;
}
leftSum += arr[i];
}
return -1;
}
}
Mid Support โ
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[] arr = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = scanner.nextInt();
}
int result = findLeftmostIndex(N, arr);
System.out.println(result);
scanner.close();
}
public static int findLeftmostIndex(int N, int[] arr) {
int totalSum = 0;
for (int value : arr) {
totalSum += value;
}
int leftSum = 0;
for (int i = 0; i < N; i++) {
totalSum -= arr[i];
if (leftSum == totalSum) {
return i;
}
leftSum += arr[i];
}
return -1;
}
}
Mid Support โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e5+10;
ll vis[N]={0},a[26]={0};
char col[N];
vector<ll>adj[N];
ll ans=0;
void dfs(ll node)
{
if(a[col[node]-'a']==0) ans++;
a[col[node]-'a']++;
vis[node]=1;
for (ll it:adj[node])
{
if(!vis[it])
dfs(it);
}
a[col[node]-'a']--;
}
signed main()
{
ll t; cin>>t;
while(t--)
{
ll n; cin>>n;
for(ll i=1;i<=n;i++)
{
adj[i].clear();
vis[i]=0;
}
for(auto&it:a) it=0;
for(ll i=1;i<=n;i++) cin>>col[i];
for(ll i=0;i<n-1;i++)
{
ll u,v; cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
ans=0;
dfs(1);
cout<<ans<<endl;
}
}
Parent node โ
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e5+10;
class dsu
{
public:
vector<ll> parent,size;
dsu(ll n) {
parent.resize(n + 1);
size.resize(n + 1,1);
for (ll i = 0; i <= n; i++) parent[i] = i;
}
ll par(ll node) {
if (node == parent[node])
return node;
return parent[node]=par(parent[node]);
}
void usize(ll u,ll v) {
ll ulp_u=par(u);
ll ulp_v=par(v);
if (ulp_u == ulp_v) return;
if (size[ulp_u] < size[ulp_v]) {
parent[ulp_u] = ulp_v;
size[ulp_v] += size[ulp_u];
}
else {
parent[ulp_v] = ulp_u;
size[ulp_u] += size[ulp_v];
}
}
};
bool prime[N];
void pre()
{
memset(prime,true,sizeof(prime));
prime[1]=0;
for(ll i=2;i*i<=N;i++)
{
if(prime[i]==1)
{
for(ll j=i*i;j<=N;j+=i)
prime[j]=0;
}
}
}
signed main()
{
pre();
ll n; cin>>n;
dsu obj(n+1);
vector<vector<ll>>g(n+1);
for(ll i=1;i<n;i++)
{
ll a,b; cin>>a>>b;
if(prime[a]==1 && prime[b]==1) continue;
else if(prime[a]==1) g[a].push_back(b);
else if(prime[b]==1) g[b].push_back(a);
else obj.usize(a,b);
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
if(prime[i])
{
ll curr=1;
for(auto rel:g[i]) curr+=obj.size[obj.par(rel)];
for(auto rel:g[i])
{
ll ex=obj.size[obj.par(rel)];
ans+=ex*(curr-ex);
curr-=ex;
}
}
}
cout<<ans<<endl;
}
Prime Tree โ
SELECT order_id, product_id, buyer
FROM quantity
WHERE quantity_ordered = ANY (SELECT 6)
ORDER BY buyer ASC;
Zepto (SQL) โ
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll solve(vector<ll>&a)
{
ll n=a.size();
ll ans=0;
unordered_map<ll,ll>mpp;
for(auto it:a) mpp[it]++;
ll i=3;
vector<ll>t;
while(i<=pow(3,21))
{
t.push_back(i);
i*=3;
}
for(ll i=0;i<n;i++)
{
for(auto it:t)
{
if(it>=a[i] && mpp.find(it-a[i])!=mpp.end()) ans+=mpp[a[i]]*mpp[it-a[i]];
}
mpp.erase(a[i]);
}
return ans;
}
signed main()
{
ll n; cin>>n;
vector<ll>a(n);
for(ll i=0;i<n;i++) cin>>a[i];
cout<<solve(a)<<endl;
}
Valid Pairs โ
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>solve(vector<ll>&a,ll n,ll k)
{
ll i=0;
while(k)
{
if(a[i]!=0)
{
a[i]--;
k--;
}
i=(i+1)%n;
}
return a;
}
signed main()
{
ll n,k; cin>>n>>k;
vector<ll>a(n);
for(ll i=0;i<=n-1;i++) cin>>a[i];
auto ans=solve(a,n,k);
for(auto it:ans) cout<<it<<" ";
cout<<endl;
}
Olympic preparation โ
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll solve(vector<ll>&a)
{
ll n=a.size();
priority_queue<ll>pq;
ll mini=LONG_MAX;
for(auto it:a)
{
if(it%2) it*=2;
mini=min(mini,it);
pq.push(it);
}
ll ans=LONG_MAX;
while(pq.top()%2==0)
{
auto it=pq.top();
pq.pop();
ans=min(ans,it-mini);
mini=min(mini,it/2);
pq.push(it/2);
}
return min(ans,pq.top()-mini);
}
signed main()
{
ll t; cin>>t;
while(t--)
{
ll n; cin>>n;
vector<ll>a(n);
for(ll i=0;i<n;i++) cin>>a[i];
cout<<solve(a)<<endl;
}
}
Array Difference
Zepto โ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
HCL Tech internship
Role : LLM Data Scientist
Batch : 2024,2025
Link : https://forms.office.com/pages/responsepage.aspx?id=N-edGDrJWk-LaG9MqZQZEn_4YzJg3wtMqTZGj64AarhUMFo0TUFTNEY2TDFHTU9XTVlHUjJOWTFaVi4u
Role : LLM Data Scientist
Batch : 2024,2025
Link : https://forms.office.com/pages/responsepage.aspx?id=N-edGDrJWk-LaG9MqZQZEn_4YzJg3wtMqTZGj64AarhUMFo0TUFTNEY2TDFHTU9XTVlHUjJOWTFaVi4u
Office
Please fill out this form
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Crework is hiring for Full Stack Engineer
Remote Opportunity
0 - 2 years experience
Monthly Salary : 50 k ( 6 LPA )
View JD : https://crework.notion.site/Job-Description-Full-Stack-Developer-c8c2ea3cf32340f1b46d4c3c5111293f?pvs=4
Hiring with assignment :
https://crework.notion.site/Assignment-Trello-Style-Task-Management-Application-0bcb3b4db4504d6199b803704e561e87?pvs=4
Submit assignment here :
https://tally.so/r/mBBRee
Assignment Completion Deadline : 31 July 2024
Remote Opportunity
0 - 2 years experience
Monthly Salary : 50 k ( 6 LPA )
View JD : https://crework.notion.site/Job-Description-Full-Stack-Developer-c8c2ea3cf32340f1b46d4c3c5111293f?pvs=4
Hiring with assignment :
https://crework.notion.site/Assignment-Trello-Style-Task-Management-Application-0bcb3b4db4504d6199b803704e561e87?pvs=4
Submit assignment here :
https://tally.so/r/mBBRee
Assignment Completion Deadline : 31 July 2024
Crework on Notion
Job Description - Full Stack Developer | Notion
About Crework Labs
๐1
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Aurva is hiring SDE intern
For 2024, 2025, 2026 grads
Location: Remote
https://wellfound.com/jobs/2892047-software-engineering-intern?utm_campaign=linkedin_syndication&utm_source=linkedin
For 2024, 2025, 2026 grads
Location: Remote
https://wellfound.com/jobs/2892047-software-engineering-intern?utm_campaign=linkedin_syndication&utm_source=linkedin
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company: ScoreMe Solutions
Location: N/A
Role: SDE
For Graduates: 2024, 2023, 2022, 2021
https://www.linkedin.com/posts/mukulgargg_dsa-hiring-sde1-activity-7222508945196691458-q9fT
Location: N/A
Role: SDE
For Graduates: 2024, 2023, 2022, 2021
https://www.linkedin.com/posts/mukulgargg_dsa-hiring-sde1-activity-7222508945196691458-q9fT
Linkedin
#dsa #hiring #sde1 #sde2 #sde #software #softwaredeveloper #springbootโฆ | Mukul Garg | 83 comments
Thanks all for overwhelming response.
We are not accepting applications anymore.
I have received lots of resume and while itโs difficult for me to reply on all of them, Iโll reach out to the ones short listed.
Thanks again!
โโโโโโโโโโโโโโโโโโโโโ
Hi Allโฆ
We are not accepting applications anymore.
I have received lots of resume and while itโs difficult for me to reply on all of them, Iโll reach out to the ones short listed.
Thanks again!
โโโโโโโโโโโโโโโโโโโโโ
Hi Allโฆ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Concentrix is hiring for the role of Associate
Expected Salary: 3-5 LPA
Apply here:
https://jobs.concentrix.com/job/phn-phn-14724270/
Expected Salary: 3-5 LPA
Apply here:
https://jobs.concentrix.com/job/phn-phn-14724270/
Global
Search for Jobs - Global
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Zeotap is hiring for Software Engineer - Intern
Expected Stipend: 7-10 LPA
Apply here:
https://jobs.lever.co/zeotap/d9da141a-91f0-4713-9eb1-ee103e7bc1d6
Expected Stipend: 7-10 LPA
Apply here:
https://jobs.lever.co/zeotap/d9da141a-91f0-4713-9eb1-ee103e7bc1d6