๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
int minCntFoun(int a[], int N)
{
int dp[N];
for(int i=0;i<N;i++){
dp[i]=-1;
}
int idxLeft;
int idxRight;
for (int i = 0; i < N; i++) {
idxLeft = max(i - a[i], 0);
idxRight = min(i + (a[i] + 1), N);
dp[idxLeft] = max(dp[idxLeft],
idxRight);
}
int cntfount = 1;
idxRight = dp[0];
int idxNext=-1;
for (int i = 0; i < N; i++)
{
idxNext = max(idxNext,
dp[i]);
if (i == idxRight)
{
cntfount++;
idxRight = idxNext;
}
}
return cntfount;
}
fountain โ
int findmaxPath(int root, int &ans, vector<int> &parent, vector<int> &values, vector<bool> &computed){
if(computed[root]) return values[root];
if(parent[root]==-1) {
computed[root]=true;
}
else{
computed[root]=true;
int parentpath = findmaxPath(parent[root], ans, parent, values, computed);
values[root] = max(parentpath+values[root], values[root]);
}
ans = max(ans, values[root]);
return values[root];
}
int bestSumDownwardTreePath(vector<int> parent, vector<int> values) {
int n=parent.size();
int ans = values[0];
vector<bool> computed(n, false);
for(int i=0; i<n; i++){
if(computed[i]) continue;
findmaxPath(i, ans, parent, values, computed);
}
return ans;
}
Best Sum Any Tree Path โ
int N = batch_a.size();
int dp[N][2];
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
dp[0][1] = 1;
for(int i = 1; i < N; i++){
// batch_a
int temp = 0;
if(batch_a[i] >= batch_a[i - 1]) temp = max(temp, dp[i - 1][0]);
if(batch_a[i] >= batch_b[i - 1]) temp = max(temp, dp[i - 1][1]);
dp[i][0] = temp + 1;
temp = 0;
if(batch_b[i] >= batch_a[i - 1]) temp = max(temp, dp[i - 1][0]);
if(batch_b[i] >= batch_b[i - 1]) temp = max(temp, dp[i - 1][1]);
dp[i][1] = temp + 1;
}
int ans = 0;
for(int i = 0; i < N; i++)
ans = max({ans, dp[i][0], dp[i][1]});
return ans;
getmaxsubarraylen
Meeshoโ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
vector<int> suffixArray(const string& s) {
int n = s.size();
vector<int> p(n), c(n);
vector<pair<char, int>> a(n);
for (int i = 0; i < n; i++) a[i] = {s[i], i};
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) p[i] = a[i].second;
c[p[0]] = 0;
for (int i = 1; i < n; i++) {
if (a[i].first == a[i - 1].first) {
c[p[i]] = c[p[i - 1]];
} else {
c[p[i]] = c[p[i - 1]] + 1;
}
}
int k = 0;
vector<int> pn(n), cn(n);
while ((1 << k) < n) {
for (int i = 0; i < n; i++) {
pn[i] = p[i] - (1 << k);
if (pn[i] < 0) pn[i] += n;
}
vector<int> cnt(n);
for (int x : c) cnt[x]++;
for (int i = 1; i < n; i++) cnt[i] += cnt[i - 1];
for (int i = n - 1; i >= 0; i--) p[--cnt[c[pn[i]]]] = pn[i];
cn[p[0]] = 0;
for (int i = 1; i < n; i++) {
pair<int, int> cur = {c[p[i]], c[(p[i] + (1 << k)) % n]};
pair<int, int> prev = {c[p[i - 1]], c[(p[i - 1] + (1 << k)) % n]};
if (cur == prev) {
cn[p[i]] = cn[p[i - 1]];
} else {
cn[p[i]] = cn[p[i - 1]] + 1;
}
}
c.swap(cn);
k++;
}
return p;
}
vector<int> lcpArray(const string& s, const vector<int>& p) {
int n = s.size();
vector<int> rank(n), lcp(n - 1);
for (int i = 0; i < n; i++) rank[p[i]] = i;
int k = 0;
for (int i = 0; i < n; i++) {
if (rank[i] == n - 1) {
k = 0;
continue;
}
int j = p[rank[i] + 1];
while (i + k < n && j + k < n && s[i + k] == s[j + k]) k++;
lcp[rank[i]] = k;
if (k > 0) k--;
}
return lcp;
}
int substringCalculator(const string& s) {
string s_ext = s + "$";
vector<int> p = suffixArray(s_ext);
vector<int> lcp = lcpArray(s_ext, p);
long long total = 0;
int n = s.size();
for (int i = 0; i < n; i++) {
total += lcp[i];
}
return (long long)n * (n + 1) / 2 - total;
}
int main() {
string s;
cin >> s;
cout << substringCalculator(s) << endl;
return 0;
}
Meesho โ
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int ceil(const vector<int>& tail, int left, int right, int x) {
while (right > left) {
int mid = left + (right - left) / 2;
if (tail[mid] >= x) {
right = mid;
} else {
left = mid + 1;
}
}
return right;
}
int MinDeletion(const vector<int>& arr, int n) {
vector<int> tail(n, 0);
tail[0] = arr[0];
int length = 1;
for (int i = 1; i < n; ++i) {
if (arr[i] > tail[length - 1]) {
tail[length] = arr[i];
length++;
} else {
int c = ceil(tail, 0, length - 1, arr[i]);
tail[c] = arr[i];
}
}
return n - length;
}
Mindeletion C++
Meesho โ
int FUNC(vector<int> &v){
unordered_set<int> st(v.begin(),v.end());
for(int i=0;i<31;i++){
if(st.find(1<<i)==st.end()){
return 1<<i;
}
}
return -1;
}
subset mexโ
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int>& A, vector<int>& B, int X, int Y) {
int N = A.size();
vector<int> dpA(N), dpB(N);
// Initial condition: Start at position 0 on either line
dpA[0] = A[0];
dpB[0] = B[0];
// Fill the dp arrays
for (int i = 1; i < N; ++i) {
dpA[i] = min(dpA[i - 1] + A[i], dpB[i - 1] + Y + A[i]);
dpB[i] = min(dpB[i - 1] + B[i], dpA[i - 1] + X + B[i]);
}
// The result is the minimum time to complete the car on either line at the last position
return min(dpA[N - 1], dpB[N - 1]);
}
int main() {
int N, X, Y;
cin >> N >> X >> Y;
vector<int> A(N), B(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
for (int i = 0; i < N; ++i) {
cin >> B[i];
}
cout << solution(A, B, X, Y) << endl;
return 0;
}
Ms task2โ
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int>& A, vector<int>& B, int X, int Y) {
int N = A.size();
vector<int> dpA(N), dpB(N);
// Initial condition: Start at position 0 on either line
dpA[0] = A[0];
dpB[0] = B[0];
// Fill the dp arrays
for (int i = 1; i < N; ++i) {
dpA[i] = min(dpA[i - 1] + A[i], dpB[i - 1] + Y + A[i]);
dpB[i] = min(dpB[i - 1] + B[i], dpA[i - 1] + X + B[i]);
}
// The result is the minimum time to complete the car on either line at the last position
return min(dpA[N - 1], dpB[N - 1]);
}
int main() {
int N, X, Y;
cin >> N >> X >> Y;
vector<int> A(N), B(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
for (int i = 0; i < N; ++i) {
cin >> B[i];
}
cout << solution(A, B, X, Y) << endl;
return 0;
}
Ms task2โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll solve(vector<int>& s, int k) {
sort(s.begin(), s.end());
int n = s.size();
vector<ll> ps(n+1, 0);
for (int i = 0; i < n; ++i) {
ps[i + 1] = ps[i] + s[i];
}
ll minEff = LLONG_MAX;
for (int i = 0; i <= n - k; ++i) {
int mIdx = i + k / 2;
int x = s[mIdx];
ll lSum = (mIdx - i) * x - (ps[mIdx] - ps[i]);
// cout << lSum <<" ";
ll rSum = (ps[i + k] - ps[mIdx + 1]) - (i + k - mIdx - 1) * x;
// cout << rSum <<" ";
ll eff = lSum + rSum;
minEff = min(minEff, eff);
}
return minEff;
}
Atlassian
findminimumeffortโ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
takeUforward | SWE Interns and FTE
https://www.linkedin.com/posts/takeuforward_hiring-wearehiring-activity-7228273874994442240-Fd3c
https://www.linkedin.com/posts/takeuforward_hiring-wearehiring-activity-7228273874994442240-Fd3c
Linkedin
๐จ WE ARE HIRING! | takeUforward
๐จ WE ARE HIRING!
We are looking for a SWE Intern and FTE. All the details mentioned in below forms. Might be closing this anytime soon!
Intern : https://lnkd.in/gJuWkEwr
FTE : https://lnkd.in/g3mRT2yx
#hiring | #wearehiring | 147 comments on LinkedIn
We are looking for a SWE Intern and FTE. All the details mentioned in below forms. Might be closing this anytime soon!
Intern : https://lnkd.in/gJuWkEwr
FTE : https://lnkd.in/g3mRT2yx
#hiring | #wearehiring | 147 comments on LinkedIn
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
MX is hiring Front-end Developer
For 2021, 2022 grads
Location: Chennai
https://mx.wd1.myworkdayjobs.com/MX-IND/job/Chennai-Tamil-Nadu-India/Software-Engineer---Frontend-Developer-Experience_R1517?source=LinkedIn
For 2021, 2022 grads
Location: Chennai
https://mx.wd1.myworkdayjobs.com/MX-IND/job/Chennai-Tamil-Nadu-India/Software-Engineer---Frontend-Developer-Experience_R1517?source=LinkedIn
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Full the Form: https://forms.gle/7mSaBWyMme7XGzW76
OR
Send your updated resume to: parnavi.srivastava@yendigital.com
OR
Send your updated resume to: parnavi.srivastava@yendigital.com
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
๐Vertex Infosoft Solutions Pvt. Ltd is urgently looking for B.tech (CS/IT) candidates with:
Excellent english communication skills ๐ฃ๏ธ for the 'Associate Engineer' position in the Technical Support department.
Interested candidates can share their CVs ๐at
careers@vertexinfosoft.com
Excellent english communication skills ๐ฃ๏ธ for the 'Associate Engineer' position in the Technical Support department.
Interested candidates can share their CVs ๐at
careers@vertexinfosoft.com
def is_valid_expression(s):
valid_chars = set("0123456789+-*/ ")
if any(c not in valid_chars for c in s):
return False
prev_char = ''
for i, c in enumerate(s.strip()):
if c in '+-*/':
if prev_char in '+-*/' or i == 0 or i == len(s.strip()) - 1:
return False
prev_char = c
return True
def evaluate_expression(s):
try:
result = eval(s)
if isinstance(result, int):
return result
else:
return -1
except ZeroDivisionError:
return -1
except Exception:
return -1
def integer_calculator(s):
s = s.strip()
if not is_valid_expression(s):
return -1
result = evaluate_expression(s)
return result
Jaguar โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
struct node {
int h[26];
int n;
}
node null;
vector<node> trie;
void addContact(string &name) {
int act = 0;
for (char c : name) {
int p = c - 'a';
if (!trie[act].h[p]) {
trie[act].h[p] = trie.size();
trie.push_back(null);
}
act = trie[act].h[p];
trie[act].n++;
}
}
int findPartial(string &prefix) {
int act = 0;
for (char c : prefix) {
int p = c - 'a';
if (!trie[act].h[p]) return 0;
act = trie[act].h[p];
}
return trie[act].n;
}
int main() {
int n;
cin >> n;
string operation, contact;
null.n = 0;
for (int i = 0; i < 26; i++) null.h[i] = 0;
trie.push_back(null);
vector<int> results;
for (int i = 0; i < n; i++) {
cin >> operation >> contact;
if (operation == "add") {
addContact(contact);
} else if (operation == "find") {
results.push_back(findPartial(contact));
}
}
for (int res : results) {
cout << res << "\n";
}
return 0;
}
Jaguar โ