#include <iostream>
#include <string>
using namespace std;
bool isGoodString(string s) {
int count = 0;
for (char c : s) {
if (c == 'a') {
count++;
} else {
count--;
}
if (count < 0) {
return false;
}
}
return count == 0;
}
int main() {
string s = "aaabbbaaa";
cout << "Is the string good? " << (isGoodString(s) ? "Yes" : "No") << endl;
return 0;
}
Count Good Triples โ
C++
HackWithInfy
#include <string>
using namespace std;
bool isGoodString(string s) {
int count = 0;
for (char c : s) {
if (c == 'a') {
count++;
} else {
count--;
}
if (count < 0) {
return false;
}
}
return count == 0;
}
int main() {
string s = "aaabbbaaa";
cout << "Is the string good? " << (isGoodString(s) ? "Yes" : "No") << endl;
return 0;
}
Count Good Triples โ
C++
HackWithInfy
๐1
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
const int MOD = 1e9 + 7;
vector<vector<int>> tree;
vector<int> a;
unordered_map<int, int> countMap;
bool checkPalindrome(unordered_map<int, int>& countMap) {
int oddCount = 0;
for (auto& it : countMap) {
if (it.second % 2 != 0) oddCount++;
if (oddCount > 1) return false;
}
return true;
}
int dfs(int node) {
int ans = 0;
countMap[a[node]]++;
if (checkPalindrome(countMap)) {
ans = 1;
}
for (auto& child : tree[node]) {
ans += dfs(child);
ans %= MOD;
}
countMap[a[node]]--; // Backtrack to remove the current node's count
return ans;
}
int main() {
int n;
cin >> n;
tree.resize(n + 1);
a.resize(n + 1);
vector<int> par(n + 1);
for (int i = 2; i <= n; i++) {
cin >> par[i];
tree[par[i]].push_back(i);
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = dfs(1);
cout << ans << endl;
return 0;
}
C++ code Palindromic subtrees
#include <vector>
#include <unordered_map>
using namespace std;
const int MOD = 1e9 + 7;
vector<vector<int>> tree;
vector<int> a;
unordered_map<int, int> countMap;
bool checkPalindrome(unordered_map<int, int>& countMap) {
int oddCount = 0;
for (auto& it : countMap) {
if (it.second % 2 != 0) oddCount++;
if (oddCount > 1) return false;
}
return true;
}
int dfs(int node) {
int ans = 0;
countMap[a[node]]++;
if (checkPalindrome(countMap)) {
ans = 1;
}
for (auto& child : tree[node]) {
ans += dfs(child);
ans %= MOD;
}
countMap[a[node]]--; // Backtrack to remove the current node's count
return ans;
}
int main() {
int n;
cin >> n;
tree.resize(n + 1);
a.resize(n + 1);
vector<int> par(n + 1);
for (int i = 2; i <= n; i++) {
cin >> par[i];
tree[par[i]].push_back(i);
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = dfs(1);
cout << ans << endl;
return 0;
}
C++ code Palindromic subtrees
#include <iostream>
#include <vector>
#include <string>
using namespace std;
const int MOD = 1e9 + 7;
int countGoodStrings(int N, int M, string S) {
long long totalGoodStrings = 1;
for (int i = 0; i < N; i++) {
totalGoodStrings = (totalGoodStrings * M) % MOD;
}
return totalGoodStrings;
}
int main() {
int N, M;
cin >> N >> M;
string S;
cin >> S;
int result = countGoodStrings(N, M, S);
cout << result << endl;
return 0;
}
C++
Good strings code
HackWithInfyโ
#include <vector>
#include <string>
using namespace std;
const int MOD = 1e9 + 7;
int countGoodStrings(int N, int M, string S) {
long long totalGoodStrings = 1;
for (int i = 0; i < N; i++) {
totalGoodStrings = (totalGoodStrings * M) % MOD;
}
return totalGoodStrings;
}
int main() {
int N, M;
cin >> N >> M;
string S;
cin >> S;
int result = countGoodStrings(N, M, S);
cout << result << endl;
return 0;
}
C++
Good strings code
HackWithInfyโ
๐2
To solve this problem, we can use dynamic programming and traverse the tree formed by the cities and roads. We'll maintain two arrays: one for the maximum potatoes Bob can buy if he visits a city (
Here's the Python code to achieve this:
This function
max_potatoes
) and another for the maximum potatoes Bob can buy if the city is on his way (max_potatoes_on_way
).Here's the Python code to achieve this:
def max_potatoes(N, U, V, M, C, B, W):
# Build adjacency list representation of the tree
adj_list = [[] for _ in range(N+1)]
for i in range(N-1):
adj_list[U[i]].append(V[i])
adj_list[V[i]].append(U[i])
# Initialize arrays to store maximum potatoes
max_potatoes = [0] * (N+1)
max_potatoes_on_way = [0] * (N+1)
# Perform DFS traversal
def dfs(node, parent):
potatoes_bought = 0
potatoes_on_way = 0
# Check if current city is in the list of cities to visit
if node in W:
potatoes_bought = M[node] if C[node] <= B else 0
potatoes_on_way = M[node]
# Traverse children
for child in adj_list[node]:
if child != parent:
child_potatoes, child_potatoes_on_way = dfs(child, node)
potatoes_bought += child_potatoes
potatoes_on_way += max(child_potatoes, child_potatoes_on_way)
# Update maximum potatoes arrays
max_potatoes[node] = potatoes_bought
max_potatoes_on_way[node] = potatoes_on_way
return potatoes_bought, potatoes_on_way
dfs(W[0], -1) # Start DFS traversal from the first city in the list
return max(max_potatoes_on_way)
# Example usage:
N = 7
U = [1, 1, 2, 2, 3, 4]
V = [2, 3, 4, 5, 6, 7]
M = [10, 20, 30, 40, 50, 60, 70]
C = [5, 10, 15, 20, 25, 30, 35]
B = 60
W = [1, 2, 3, 4, 5, 6, 7]
print(max_potatoes(N, U, V, M, C, B, W)) # Output: 170
This function
max_potatoes
takes inputs N, U, V, M, C, B, and W as described in the problem statement and returns the maximum potatoes Bob can buy. It performs a depth-first search (DFS) traversal of the tree formed by the cities and roads, calculating the maximum potatoes Bob can buy if he visits a city or if it's on his way. Finally, it returns the maximum of potatoes on the way.โค2๐2
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
int N, Q;
// cout<<"enter n\n";
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
// cout<<"enter q\n";
cin >> Q;
long long sum = 0;
for (int q = 0; q < Q; ++q) {
//cout<<"Enter query " << q <<endl;
int type, L, R, X, i , zero1 , zero2;
cin >> type;
if (type == 1) {
cin >> L >> R >> X;
for (int j = L-1; j < R; ++j) {
A[j] = min(A[j], X);
}
} else if (type == 2) {
cin >> i >> zero1 >>zero2;
//cout<<"value of i and A[i] is " << i<<" " << A[i]<<endl;
sum = (sum + A[i - 1]) % MOD;
}
}
cout << sum << endl;
return 0;
}
Replace by minimum
#include <vector>
#include <algorithm>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
int N, Q;
// cout<<"enter n\n";
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
// cout<<"enter q\n";
cin >> Q;
long long sum = 0;
for (int q = 0; q < Q; ++q) {
//cout<<"Enter query " << q <<endl;
int type, L, R, X, i , zero1 , zero2;
cin >> type;
if (type == 1) {
cin >> L >> R >> X;
for (int j = L-1; j < R; ++j) {
A[j] = min(A[j], X);
}
} else if (type == 2) {
cin >> i >> zero1 >>zero2;
//cout<<"value of i and A[i] is " << i<<" " << A[i]<<endl;
sum = (sum + A[i - 1]) % MOD;
}
}
cout << sum << endl;
return 0;
}
Replace by minimum
๐1
MOD = 10**9 + 7
def count_good_subsequences(arr, K):
n = len(arr)
dp = [[0] * (K + 2) for _ in range(n + 1)]
for i in range(1, n + 1):
dp[i][0] = 1
for j in range(1, K + 2):
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD
result = 0
for i in range(n):
for j in range(K + 1):
left = i - j
if left >= 0:
result = (result + dp[left][K - j]) % MOD
return result
# Example usage:
N = int(input())
A = [int(input()) for _ in range(N)]
K = int(input())
print(count_good_subsequences(A, K))
Count Subsequence
def count_good_subsequences(arr, K):
n = len(arr)
dp = [[0] * (K + 2) for _ in range(n + 1)]
for i in range(1, n + 1):
dp[i][0] = 1
for j in range(1, K + 2):
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD
result = 0
for i in range(n):
for j in range(K + 1):
left = i - j
if left >= 0:
result = (result + dp[left][K - j]) % MOD
return result
# Example usage:
N = int(input())
A = [int(input()) for _ in range(N)]
K = int(input())
print(count_good_subsequences(A, K))
Count Subsequence
MOD = 10**9 + 7
def solve(arrival_departure):
arrival_departure.sort(key=lambda x: x[1])
prev_departure = -1
total_stations = 0
for arrival, departure in arrival_departure:
if arrival > prev_departure:
total_stations += 1
prev_departure = departure
return total_stations % MOD
def main():
N = int(input())
arrival_departure = []
for _ in range(N):
arrival, departure = map(int, input().split())
arrival_departure.append((arrival, departure))
result = solve(arrival_departure)
print(result)
if name == "main":
main()
Trains Code
Python
HackWithInfy
def solve(arrival_departure):
arrival_departure.sort(key=lambda x: x[1])
prev_departure = -1
total_stations = 0
for arrival, departure in arrival_departure:
if arrival > prev_departure:
total_stations += 1
prev_departure = departure
return total_stations % MOD
def main():
N = int(input())
arrival_departure = []
for _ in range(N):
arrival, departure = map(int, input().split())
arrival_departure.append((arrival, departure))
result = solve(arrival_departure)
print(result)
if name == "main":
main()
Trains Code
Python
HackWithInfy
๐1
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int getSmallestArea(vector<vector<int>>& grid) {
int rows = grid.size();
if (rows == 0) return 0;
int cols = grid[0].size();
if (cols == 0) return 0;
set<int> rowsSet, colsSet;
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
if (grid[i][j] == 1) {
rowsSet.insert(i);
colsSet.insert(j);
}
}
}
int width = colsSet.empty() ? 0 : *colsSet.rbegin() - *colsSet.begin() + 1;
int height = rowsSet.empty() ? 0 : *rowsSet.rbegin() - *rowsSet.begin() + 1;
return width * height;
}
shipping spaceโ
Salesforce
#include <vector>
#include <set>
using namespace std;
int getSmallestArea(vector<vector<int>>& grid) {
int rows = grid.size();
if (rows == 0) return 0;
int cols = grid[0].size();
if (cols == 0) return 0;
set<int> rowsSet, colsSet;
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
if (grid[i][j] == 1) {
rowsSet.insert(i);
colsSet.insert(j);
}
}
}
int width = colsSet.empty() ? 0 : *colsSet.rbegin() - *colsSet.begin() + 1;
int height = rowsSet.empty() ? 0 : *rowsSet.rbegin() - *rowsSet.begin() + 1;
return width * height;
}
shipping spaceโ
Salesforce
All tc passed this code
Request Parser โ
def getResponses(valid_auth_tokens, requests):
# Write your code here
res = []
for request in requests:
rt,url = request
params = url.split('?')[1].split('&')
au = None
csr = None
for elon in params:
key,value = elon.split('=')
if key=='token':
au = value
elif key =='csrf':
csr = value
if au not in valid_auth_tokens:
res.append("INVALID")
elif rt=='POST' and (csr is None or not csr.isalnum() or len(csr)<8):
res.append("INVALID")
else:
rss = "VALID"
for elon in params:
key,value = elon.split('=')
if key!='token' and key!='csrf':
rss+=f",{key},{value}"
res.append(rss)
return res
Request Parser โ
๐1
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
๐2
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
๐Techjet is Hiring Data Engineer Internship
Batch: 2024, 2025
Expected Stipend: 30K per month
๐Apply here-
https://www.instahyre.com/job-289451-data-engineer-internship-at-techjet-work-from-home/
๐Orangewood is Hiring SDE Intern
Batch: 2024, 2025
Batch: Expected Stipend 20k - 25K per month
๐Apply here-
https://orangewood.keka.com/careers/jobdetails/39183
Batch: 2024, 2025
Expected Stipend: 30K per month
๐Apply here-
https://www.instahyre.com/job-289451-data-engineer-internship-at-techjet-work-from-home/
๐Orangewood is Hiring SDE Intern
Batch: 2024, 2025
Batch: Expected Stipend 20k - 25K per month
๐Apply here-
https://orangewood.keka.com/careers/jobdetails/39183
Instahyre
Data Engineer (Internship) job at Techjet - Instahyre
Techjet is looking for a Data Engineer (Internship) in Work From Home with 0-0 years of experience in Big Data / DWH / ETL, Kafka, AWS, Terraform, Data Streaming, CI - CD, etc. Apply today and get your dream job at Techjet!
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
๐BCG is hiring Junior Data Analyst
Experience: freshers
๐Apply here:
https://careers.bcg.com/job/BCG1US10063926EXTERNALENUS/Junior-Data-Analyst-X-Delivery
Experience: freshers
๐Apply here:
https://careers.bcg.com/job/BCG1US10063926EXTERNALENUS/Junior-Data-Analyst-X-Delivery
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
๐Groww is Hiring for SDE (Databases) Intern
Batch: 2024, 2025
Apply here-
https://www.linkedin.com/jobs/view/3879712088/
๐Unacademy is Hiring for Prompt Engineer Intern
Batch: 2024, 2025
Apply here-
https://www.linkedin.com/jobs/view/3885103611/
Batch: 2024, 2025
Apply here-
https://www.linkedin.com/jobs/view/3879712088/
๐Unacademy is Hiring for Prompt Engineer Intern
Batch: 2024, 2025
Apply here-
https://www.linkedin.com/jobs/view/3885103611/
Linkedin
Groww hiring SDE Intern (Databases) in Greater Bengaluru Area | LinkedIn
Posted 6:20:11 AM. About GrowwWe are a passionate group of people focused on making financial services accessible toโฆSee this and similar jobs on LinkedIn.
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
๐EY is hiring for Associate Software Engineer
Expected Salary: 4-8 LPA
๐Apply here:
https://eyglobal.yello.co/jobs/8IHXFasbjHXJfZj5LjWIOg?job_board_id=c1riT--B2O-KySgYWsZO1Q&src=JB-10820
Expected Salary: 4-8 LPA
๐Apply here:
https://eyglobal.yello.co/jobs/8IHXFasbjHXJfZj5LjWIOg?job_board_id=c1riT--B2O-KySgYWsZO1Q&src=JB-10820
๐1
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int count_vowels(string str) {
int count = 0;
string vowels = "aeiou";
for (char ch : str) {
if (vowels.find(tolower(ch)) != string::npos) {
count++;
}
}
return count;
}
vector<string> determine_winner(vector<string> strings) {
vector<string> winners;
for (string str : strings) {
if (count_vowels(str) == 0) {
winners.push_back("Chris");
} else {
winners.push_back("Alex");
}
}
return winners;
}.
System and Strings
JPMC โ
#include <vector>
#include <string>
using namespace std;
int count_vowels(string str) {
int count = 0;
string vowels = "aeiou";
for (char ch : str) {
if (vowels.find(tolower(ch)) != string::npos) {
count++;
}
}
return count;
}
vector<string> determine_winner(vector<string> strings) {
vector<string> winners;
for (string str : strings) {
if (count_vowels(str) == 0) {
winners.push_back("Chris");
} else {
winners.push_back("Alex");
}
}
return winners;
}.
System and Strings
JPMC โ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Crux is hiring for a Fresher entry level Data Analyst! (Fresh grads can also apply)
Min experience: 0 years
Apply:-https://www.ycombinator.com/companies/crux/jobs/6woKQya-data-analyst?
Min experience: 0 years
Apply:-https://www.ycombinator.com/companies/crux/jobs/6woKQya-data-analyst?
Y Combinator
Data Analyst at Crux
What exactly will you be working on?
1. Customer Solutioning & Onboarding
Assisting the sales team in conducting demos for prospects on their dataset. This involves:
- Coordinating with prospects to understand the nuances of their data schema
- Connectingโฆ
1. Customer Solutioning & Onboarding
Assisting the sales team in conducting demos for prospects on their dataset. This involves:
- Coordinating with prospects to understand the nuances of their data schema
- Connectingโฆ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
IKEA is hiring Data Analyst!
Qualifications: Bachelorโs/ Master's Degree
Salary: 8 LPA (Expected)
Experience: Freshers/ Experienced
Location: Bengaluru, India
๐Apply Now: https://ikea.avature.net/en_BW/External/JobDetail?id=227458%3Fsource%3DLinkedIn&source=LinkedIn
All the best ๐๐
Qualifications: Bachelorโs/ Master's Degree
Salary: 8 LPA (Expected)
Experience: Freshers/ Experienced
Location: Bengaluru, India
๐Apply Now: https://ikea.avature.net/en_BW/External/JobDetail?id=227458%3Fsource%3DLinkedIn&source=LinkedIn
All the best ๐๐
ikea.avature.net
External Careers Global NEW
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name: BarRaiser
๐ Job Title: Backend Intern
โ๐ป YOE: 2023 and 2024
โก๏ธ Apply: https://www.linkedin.com/jobs/view/internship-backend-at-barraiser-3876417663/
Please do share in your college grps and in case you are applying please react on this post:) ๐โค๏ธ
๐ Job Title: Backend Intern
โ๐ป YOE: 2023 and 2024
โก๏ธ Apply: https://www.linkedin.com/jobs/view/internship-backend-at-barraiser-3876417663/
Please do share in your college grps and in case you are applying please react on this post:) ๐โค๏ธ
int minimumKeypresses(string s) {
unordered_map<char, int> counts;
for (char ch : s) {
counts[ch]++;
}
vector<int> frequencies;
for (const auto& kvp : counts) {
frequencies.push_back(kvp.second);
}
sort(frequencies.begin(), frequencies.end(), greater<int>());
vector<int> remain {9, 9, 9};
int i = 0, total = 0;
for (int count : frequencies) {
total += count * (i + 1);
remain[i]--;
if (remain[i] == 0) {
i++;
}
}
return total;
}
Amazon โ
unordered_map<char, int> counts;
for (char ch : s) {
counts[ch]++;
}
vector<int> frequencies;
for (const auto& kvp : counts) {
frequencies.push_back(kvp.second);
}
sort(frequencies.begin(), frequencies.end(), greater<int>());
vector<int> remain {9, 9, 9};
int i = 0, total = 0;
for (int count : frequencies) {
total += count * (i + 1);
remain[i]--;
if (remain[i] == 0) {
i++;
}
}
return total;
}
Amazon โ