#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const int MOD = 1000000007;
int minLampsToLightRoad(int num_positions, int num_lamps, vector<int>& lamp_positions, vector<int>& left_reach, vector<int>& right_reach, vector<pair<int, int>>& queries) {
// Step 1: Create intervals for each lamp
vector<pair<int, int>> intervals;
for (int i = 0; i < num_lamps; ++i) {
intervals.push_back({lamp_positions[i] - left_reach[i], lamp_positions[i] + right_reach[i]});
}
// Step 2: Sort intervals based on starting position
sort(intervals.begin(), intervals.end());
// Precompute the farthest reach for each starting point
vector<pair<int, int>> max_reach_from_start;
int current_max_reach = -1;
for (const auto& interval : intervals) {
int start = interval.first;
int end = interval.second;
if (max_reach_from_start.empty() start > max_reach_from_start.back().first) {
max_reach_from_start.push_back({start, end});
}
current_max_reach = max(current_max_reach, end);
max_reach_from_start.back().second = current_max_reach;
}
auto min_lamps_needed = [&](int query_left, int query_right) {
int count = 0;
int max_reach = query_left;
while (max_reach <= query_right) {
auto it = upper_bound(max_reach_from_start.begin(), max_reach_from_start.end(), make_pair(max_reach, INT_MAX));
if (it == max_reach_from_start.begin() prev(it)->first > max_reach) {
return -1;
}
int next_max_reach = prev(it)->second;
if (next_max_reach <= max_reach) {
return -1;
}
max_reach = next_max_reach + 1;
count++;
if (max_reach > query_right) {
break;
}
}
return max_reach > query_right ? count : -1;
};
// Step 3: Process each query and sum up the results
int result_sum = 0;
for (const auto& query : queries) {
int result = min_lamps_needed(query.first, query.second);
if (result != -1) {
result_sum += result;
result_sum %= MOD;
}
}
return result_sum;
}
lightning lamp code , all cases are passing
@allcoding1
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const int MOD = 1000000007;
int minLampsToLightRoad(int num_positions, int num_lamps, vector<int>& lamp_positions, vector<int>& left_reach, vector<int>& right_reach, vector<pair<int, int>>& queries) {
// Step 1: Create intervals for each lamp
vector<pair<int, int>> intervals;
for (int i = 0; i < num_lamps; ++i) {
intervals.push_back({lamp_positions[i] - left_reach[i], lamp_positions[i] + right_reach[i]});
}
// Step 2: Sort intervals based on starting position
sort(intervals.begin(), intervals.end());
// Precompute the farthest reach for each starting point
vector<pair<int, int>> max_reach_from_start;
int current_max_reach = -1;
for (const auto& interval : intervals) {
int start = interval.first;
int end = interval.second;
if (max_reach_from_start.empty() start > max_reach_from_start.back().first) {
max_reach_from_start.push_back({start, end});
}
current_max_reach = max(current_max_reach, end);
max_reach_from_start.back().second = current_max_reach;
}
auto min_lamps_needed = [&](int query_left, int query_right) {
int count = 0;
int max_reach = query_left;
while (max_reach <= query_right) {
auto it = upper_bound(max_reach_from_start.begin(), max_reach_from_start.end(), make_pair(max_reach, INT_MAX));
if (it == max_reach_from_start.begin() prev(it)->first > max_reach) {
return -1;
}
int next_max_reach = prev(it)->second;
if (next_max_reach <= max_reach) {
return -1;
}
max_reach = next_max_reach + 1;
count++;
if (max_reach > query_right) {
break;
}
}
return max_reach > query_right ? count : -1;
};
// Step 3: Process each query and sum up the results
int result_sum = 0;
for (const auto& query : queries) {
int result = min_lamps_needed(query.first, query.second);
if (result != -1) {
result_sum += result;
result_sum %= MOD;
}
}
return result_sum;
}
lightning lamp code , all cases are passing
@allcoding1
π2
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void dfs(int node, int parent, const vector<vector<int>>& tree, const vector<int>& A, int depth, int& maxDepth) {
maxDepth = max(maxDepth, depth);
for (int child : tree[node]) {
if (child != parent) {
if ((A[node] ^ A[child]) < A[node] && (A[node] ^ A[child]) < A[child]) {
dfs(child, node, tree, A, depth + 1, maxDepth);
}
}
}
}
int main() {
int N;
cin >> N;
vector<int> A(N + 1);
vector<int> P(N + 1);
vector<vector<int>> tree(N + 1);
// Read values array
for (int i = 1; i <= N; ++i) {
cin >> A[i];
}
// Read parent array and buildthe tree
for (int i = 2; i <= N; ++i) { // P[1] is root with P[1] = 0, so start from 2
cin >> P[i];
tree[P[i]].push_back(i);
tree[i].push_back(P[i]);
}
int maxDepth = 0;
dfs(1, 0, tree, A, 1, maxDepth);
cout << maxDepth << endl;
return 0;
}
@allcoding1
#include <vector>
#include <algorithm>
using namespace std;
void dfs(int node, int parent, const vector<vector<int>>& tree, const vector<int>& A, int depth, int& maxDepth) {
maxDepth = max(maxDepth, depth);
for (int child : tree[node]) {
if (child != parent) {
if ((A[node] ^ A[child]) < A[node] && (A[node] ^ A[child]) < A[child]) {
dfs(child, node, tree, A, depth + 1, maxDepth);
}
}
}
}
int main() {
int N;
cin >> N;
vector<int> A(N + 1);
vector<int> P(N + 1);
vector<vector<int>> tree(N + 1);
// Read values array
for (int i = 1; i <= N; ++i) {
cin >> A[i];
}
// Read parent array and buildthe tree
for (int i = 2; i <= N; ++i) { // P[1] is root with P[1] = 0, so start from 2
cin >> P[i];
tree[P[i]].push_back(i);
tree[i].push_back(P[i]);
}
int maxDepth = 0;
dfs(1, 0, tree, A, 1, maxDepth);
cout << maxDepth << endl;
return 0;
}
@allcoding1
π2
def main():
import sys
input = sys.stdin.read
data = input().split('\n')
S = data[0].strip()
N = int(data[1].strip())
W = []
for i in range(N):
W.append(data[2 + i].strip())
freqS = get_frequency(S)
count = 0
for w in W:
if is_valid_anagram_subsequence(freqS, w):
count += 1
print(count)
def get_frequency(S):
freq = [0] * 26
for c in S:
freq[ord(c) - ord('a')] += 1
return freq
def is_valid_anagram_subsequence(freqS, w):
freqW = [0] * 26
for c in w:
freqW[ord(c) - ord('a')] += 1
for i in range(26):
if freqW[i] > freqS[i]:
return False
return True
if name == "main":
main()
// MInimal subarray length
@allcoding1
import sys
input = sys.stdin.read
data = input().split('\n')
S = data[0].strip()
N = int(data[1].strip())
W = []
for i in range(N):
W.append(data[2 + i].strip())
freqS = get_frequency(S)
count = 0
for w in W:
if is_valid_anagram_subsequence(freqS, w):
count += 1
print(count)
def get_frequency(S):
freq = [0] * 26
for c in S:
freq[ord(c) - ord('a')] += 1
return freq
def is_valid_anagram_subsequence(freqS, w):
freqW = [0] * 26
for c in w:
freqW[ord(c) - ord('a')] += 1
for i in range(26):
if freqW[i] > freqS[i]:
return False
return True
if name == "main":
main()
// MInimal subarray length
@allcoding1
π1
def GetAnswer(N, A, B, P):
dp = [0] * (N + 1)
max_d = 0
for i in range(N - 1, -1, -1):
max_p = P[i]
min_p = P[i]
for j in range(1, B + 1):
if i + j <= N:
max_p = max(max_p, P[i + j - 1])
min_p = min(min_p, P[i + j - 1])
max_d = max(max_d, max_p - min_p)
if i + 1 == N:
dp[i] = max(dp[i], max_d)
else:
dp[i] = max(dp[i], max_d, dp[i + 1])
return dp[0]
import sys
input = sys.stdin.read
data = input().split()
N = int(data[0])
A = int(data[1])
B = int(data[2])
P = list(map(int, data[3:]))
result = GetAnswer(N, A, B, P)
print(result)
// XOR formaating code
@allcoding1
dp = [0] * (N + 1)
max_d = 0
for i in range(N - 1, -1, -1):
max_p = P[i]
min_p = P[i]
for j in range(1, B + 1):
if i + j <= N:
max_p = max(max_p, P[i + j - 1])
min_p = min(min_p, P[i + j - 1])
max_d = max(max_d, max_p - min_p)
if i + 1 == N:
dp[i] = max(dp[i], max_d)
else:
dp[i] = max(dp[i], max_d, dp[i + 1])
return dp[0]
import sys
input = sys.stdin.read
data = input().split()
N = int(data[0])
A = int(data[1])
B = int(data[2])
P = list(map(int, data[3:]))
result = GetAnswer(N, A, B, P)
print(result)
// XOR formaating code
@allcoding1
public static int solve(int N, int[] A) {
int t = 0;
for (int num : A) {
t += num;
}
int x = 0;
int y = 0;
for (int i = 0; i < N; i++) {
int res = t - x - A[i];
if (x == res) {
y++;
}
x += A[i];
}
return y;
}
//Equilibrium Point
@allcoding1
int t = 0;
for (int num : A) {
t += num;
}
int x = 0;
int y = 0;
for (int i = 0; i < N; i++) {
int res = t - x - A[i];
if (x == res) {
y++;
}
x += A[i];
}
return y;
}
//Equilibrium Point
@allcoding1
π1
def f(S):
n = len(S)
lf, rf = {}, {}
ls, rs = set(), set()
# Initialize the rf map and rs with the entire string S
for c in S:
rf[c] = rf.get(c, 0) + 1
rs.add(c)
mx = 0
# Traverse the string and adjust the ls and rs sets and maps
for i in range(n - 1):
c = S[i]
lf[c] = lf.get(c, 0) + 1
rf[c] -= 1
if rf[c] == 0:
rs.remove(c)
ls.add(c)
cs = len(ls) + len(rs)
mx = max(mx, cs)
return n - mx
// spilit screen
@allcoding1_official
n = len(S)
lf, rf = {}, {}
ls, rs = set(), set()
# Initialize the rf map and rs with the entire string S
for c in S:
rf[c] = rf.get(c, 0) + 1
rs.add(c)
mx = 0
# Traverse the string and adjust the ls and rs sets and maps
for i in range(n - 1):
c = S[i]
lf[c] = lf.get(c, 0) + 1
rf[c] -= 1
if rf[c] == 0:
rs.remove(c)
ls.add(c)
cs = len(ls) + len(rs)
mx = max(mx, cs)
return n - mx
// spilit screen
@allcoding1_official
π1
All codes are available
To easily find out ur codes
Once check it ππ
https://www.instagram.com/allcoding1_official?igsh=ZHJpNXdpeWh1d2No
To easily find out ur codes
Once check it ππ
https://www.instagram.com/allcoding1_official?igsh=ZHJpNXdpeWh1d2No
π1
π―Wells Fargo Hiring Fresher For Analytics Associate
Location: Hyderabad
Qualification: Bachelors / Masterβs degree
Work Experience : Fresher - 1 Year
Salary : 10 - 11 LPA
Apply Now:- https://wd1.myworkdaysite.com/recruiting/wf/WellsFargoJobs/job/Hyderabad-India/Analytics-Associate_R-381215
Telegram:- @allcoding1
Location: Hyderabad
Qualification: Bachelors / Masterβs degree
Work Experience : Fresher - 1 Year
Salary : 10 - 11 LPA
Apply Now:- https://wd1.myworkdaysite.com/recruiting/wf/WellsFargoJobs/job/Hyderabad-India/Analytics-Associate_R-381215
Telegram:- @allcoding1
π3
Mitsogo is hiring Fresher
Apply link π
https://boards.greenhouse.io/mitsogoinc/jobs/4045384008?gh_src=eacea7cc8us
Apply link π
https://boards.greenhouse.io/mitsogoinc/jobs/4045384008?gh_src=eacea7cc8us
π2β€1
Adobe is hiring for SDE l role |
0 - 2 years experience | Noida location | CTC : 12 - 20 LPA ( expected )
https://careers.adobe.com/us/en/job/ADOBUSR146901EXTERNALENUS/Software-Development-Engineer?utm_medium=phenom-feeds&source=LinkedIn&utm_source=linkedin
0 - 2 years experience | Noida location | CTC : 12 - 20 LPA ( expected )
https://careers.adobe.com/us/en/job/ADOBUSR146901EXTERNALENUS/Software-Development-Engineer?utm_medium=phenom-feeds&source=LinkedIn&utm_source=linkedin
π1
miniOrange is hiring for Software Engineer Java
2024/2023/2022 batches eligible
Location : Pune
Last date to apply : 6 PM, 10 July 2024
CTC : 6 - 8 LPA ( expected )
Apply Now :-
https://www.miniorange.com/career/hiring-drive
2024/2023/2022 batches eligible
Location : Pune
Last date to apply : 6 PM, 10 July 2024
CTC : 6 - 8 LPA ( expected )
Apply Now :-
https://www.miniorange.com/career/hiring-drive
π2
Interview Kickstart is hiring for Frontend Engineer I and II | 1 - 4 years experience | Remote |
Apply Now:-
https://interviewkickstart.keka.com/careers/jobdetails/45540
Apply Now:-
https://interviewkickstart.keka.com/careers/jobdetails/45540
π1
public static int findEarliestMeetingTime(List<List<int[]>> schedules, int length) {
int DAY_END = 24 * 60;
List<int[]> allMeetings = new ArrayList<>();
for (List<int[]> employeeMeetings : schedules) {
allMeetings.addAll(employeeMeetings);
}
Collections.sort(allMeetings, (a, b) -> Integer.compare(a[0], b[0]));
int earliestAvailable = 0;
for (int[] meeting : allMeetings) {
if (earliestAvailable + length <= meeting[0]) {
return earliestAvailable;
}
earliestAvailable = Math.max(earliestAvailable, meeting[1]);
}
if (earliestAvailable + length <= DAY_END) {
return earliestAvailable;
}
return -1;
}
int DAY_END = 24 * 60;
List<int[]> allMeetings = new ArrayList<>();
for (List<int[]> employeeMeetings : schedules) {
allMeetings.addAll(employeeMeetings);
}
Collections.sort(allMeetings, (a, b) -> Integer.compare(a[0], b[0]));
int earliestAvailable = 0;
for (int[] meeting : allMeetings) {
if (earliestAvailable + length <= meeting[0]) {
return earliestAvailable;
}
earliestAvailable = Math.max(earliestAvailable, meeting[1]);
}
if (earliestAvailable + length <= DAY_END) {
return earliestAvailable;
}
return -1;
}
π3