SinglyLinkedListNode* findLongestList(SinglyLinkedListNode* head) {
if (!head) return nullptr;
SinglyLinkedListNode* curr = head;
SinglyLinkedListNode* start = head;
SinglyLinkedListNode* bestStart = head;
int length = 1;
int bestLength = 1;
while (curr->next) {
if (curr->data >= curr->next->data) {
length++;
} else {
if (length > bestLength) {
bestLength = length;
bestStart = start;
}
length = 1;
start = curr->next;
}
curr = curr->next;
}
if (length > bestLength) {
bestLength = length;
bestStart = start;
}
SinglyLinkedListNode* temp = bestStart;
for (int i = 1; i < bestLength && temp; i++) {
temp = temp->next;
}
if (temp) {
temp->next = nullptr;
}
return bestStart;
}
Amazon OA| AWS Databased
C++โ
if (!head) return nullptr;
SinglyLinkedListNode* curr = head;
SinglyLinkedListNode* start = head;
SinglyLinkedListNode* bestStart = head;
int length = 1;
int bestLength = 1;
while (curr->next) {
if (curr->data >= curr->next->data) {
length++;
} else {
if (length > bestLength) {
bestLength = length;
bestStart = start;
}
length = 1;
start = curr->next;
}
curr = curr->next;
}
if (length > bestLength) {
bestLength = length;
bestStart = start;
}
SinglyLinkedListNode* temp = bestStart;
for (int i = 1; i < bestLength && temp; i++) {
temp = temp->next;
}
if (temp) {
temp->next = nullptr;
}
return bestStart;
}
Amazon OA| AWS Databased
C++โ
long findTotalExecutionTime(vector<int>& execution) {
int n = execution.size();
vector<int> original = execution;
long totalTime = 0;
unordered_map<int, list<int>> origIndicesMap;
for (int i = 0; i < n; i++) {
origIndicesMap[original[i]].push_back(i);
}
for (int i = 0; i < n; i++) {
totalTime += execution[i];
if (origIndicesMap[original[i]].size() > 1) {
int reducedValue = ceil((double)execution[i] / 2);
for (int idx : origIndicesMap[original[i]]) {
if (idx != i) {
execution[idx] = reducedValue;
}
}
}
}
return totalTime;
}
Amazon
C++ โ
int n = execution.size();
vector<int> original = execution;
long totalTime = 0;
unordered_map<int, list<int>> origIndicesMap;
for (int i = 0; i < n; i++) {
origIndicesMap[original[i]].push_back(i);
}
for (int i = 0; i < n; i++) {
totalTime += execution[i];
if (origIndicesMap[original[i]].size() > 1) {
int reducedValue = ceil((double)execution[i] / 2);
for (int idx : origIndicesMap[original[i]]) {
if (idx != i) {
execution[idx] = reducedValue;
}
}
}
}
return totalTime;
}
Amazon
C++ โ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Linkedin
iSteer hiring Data Scientist in Bengaluru, Karnataka, India | LinkedIn
Posted 5:27:11 AM. AppSteer is a cloud-native SaaS that empowers Organizations to rapidly create business applicationsโฆ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)
Spring-works is Hiring !!
Role: iOS Developer
Experience: 0-1 Years
Stipend: 25K per Month
Location: Remote
Apply here- https://springrecruit.com/applynow/Springworks8989
Role: iOS Developer
Experience: 0-1 Years
Stipend: 25K per Month
Location: Remote
Apply here- https://springrecruit.com/applynow/Springworks8989
SpringRecruit
__OG_TITLE__
__OG_DESCRIPTION__
class Solution {
public:
bool isAnagram(string s, string t) {
sort(s.begin(), s.end());
sort(t.begin(), t.end());
return s == t;
}
};
int number = 15;
int n = (int)(log2(number));
// binary output
// using the inbuilt function
cout << "the binary number is : "
<< bitset<64>(number).to_string().substr(64 - n
- 1);
}
Slb solution โ
public:
bool isAnagram(string s, string t) {
sort(s.begin(), s.end());
sort(t.begin(), t.end());
return s == t;
}
};
int number = 15;
int n = (int)(log2(number));
// binary output
// using the inbuilt function
cout << "the binary number is : "
<< bitset<64>(number).to_string().substr(64 - n
- 1);
}
Slb solution โ
#include<bits/stdc++.h>
using namespace std;
int findMin(vector<int>& nums) {
int low = 0, high = nums.size() - 1, ans = INT_MAX;
while (low <= high) {
int mid = (low + high) / 2;
if (nums[low] <= nums[mid]) {
ans = std::min(ans, nums[low]);
low = mid + 1;
} else {
ans = std::min(ans, nums[mid]);
high = mid - 1;
}
}
return ans;
}
int main() {
int n;
cin >> n;
vector<int> nums(n);
for (int i = 0; i < n; ++i) {
cin >> nums[i];
}
int result = findMin(nums);
cout<< result << endl;
}
Helpshift โ
Ashley
using namespace std;
int findMin(vector<int>& nums) {
int low = 0, high = nums.size() - 1, ans = INT_MAX;
while (low <= high) {
int mid = (low + high) / 2;
if (nums[low] <= nums[mid]) {
ans = std::min(ans, nums[low]);
low = mid + 1;
} else {
ans = std::min(ans, nums[mid]);
high = mid - 1;
}
}
return ans;
}
int main() {
int n;
cin >> n;
vector<int> nums(n);
for (int i = 0; i < n; ++i) {
cin >> nums[i];
}
int result = findMin(nums);
cout<< result << endl;
}
Helpshift โ
Ashley
#include<iostream>
using namespace std;
int main() {
int sample;
cin >> sample;
for(int i = 0; i < sample; i++) {
int item;
cin >> item;
int count = 0;
while(item != 1) {
if(item % 2 == 0) {
item /= 2;
} else {
item -= 1;
}
count++;
}
cout <<count << endl;
}
return 0;
}
Multiplication tricks โ
Helpshift
using namespace std;
int main() {
int sample;
cin >> sample;
for(int i = 0; i < sample; i++) {
int item;
cin >> item;
int count = 0;
while(item != 1) {
if(item % 2 == 0) {
item /= 2;
} else {
item -= 1;
}
count++;
}
cout <<count << endl;
}
return 0;
}
Multiplication tricks โ
Helpshift
#include <bits/stdc++.h>
using namespace std;
int count(vector<int>&coins, int n, int sum)
{
int table[sum + 1];
memset(table, 0, sizeof(table));
table[0] = 1;
for (int i = 0; i < n; i++)
for (int j = coins[i]; j <= sum; j++)
table[j] += table[j - coins[i]];
return table[sum];
}
int main()
{
int n,t;
cin>>n>>t;
vector<int>L(t);
for(int i=0;i<t;i++)
{
cin>>L[i];
}
cout << count(L, t,n);
}
Helpshift โ
Goblin
using namespace std;
int count(vector<int>&coins, int n, int sum)
{
int table[sum + 1];
memset(table, 0, sizeof(table));
table[0] = 1;
for (int i = 0; i < n; i++)
for (int j = coins[i]; j <= sum; j++)
table[j] += table[j - coins[i]];
return table[sum];
}
int main()
{
int n,t;
cin>>n>>t;
vector<int>L(t);
for(int i=0;i<t;i++)
{
cin>>L[i];
}
cout << count(L, t,n);
}
Helpshift โ
Goblin
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {
vector<vector<int>> ans;
multiset<int> pq{0};
vector<pair<int, int>> points;
for(auto b: buildings){
points.push_back({b[0], -b[2]});
points.push_back({b[1], b[2]});
}
sort(points.begin(), points.end());
int ongoingHeight = 0;
for(int i = 0; i < points.size(); i++){
int currentPoint = points[i].first;
int heightAtCurrentPoint = points[i].second;
if(heightAtCurrentPoint < 0){
pq.insert(-heightAtCurrentPoint);
} else {
pq.erase(pq.find(heightAtCurrentPoint));
}
auto pqTop = *pq.rbegin();
if(ongoingHeight != pqTop){
ongoingHeight = pqTop;
ans.push_back({currentPoint, ongoingHeight});
}
}
return ans;
}
int main() {
int n;
cin >> n;
vector<vector<int>> buildings(n, vector<int>(3));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
cin >> buildings[i][j];
}
}
vector<vector<int>> result = getSkyline(buildings);
for (auto &p : result) {
cout << p[0]<<p[1]<< endl;
}
}
Skyline โ
using namespace std;
vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {
vector<vector<int>> ans;
multiset<int> pq{0};
vector<pair<int, int>> points;
for(auto b: buildings){
points.push_back({b[0], -b[2]});
points.push_back({b[1], b[2]});
}
sort(points.begin(), points.end());
int ongoingHeight = 0;
for(int i = 0; i < points.size(); i++){
int currentPoint = points[i].first;
int heightAtCurrentPoint = points[i].second;
if(heightAtCurrentPoint < 0){
pq.insert(-heightAtCurrentPoint);
} else {
pq.erase(pq.find(heightAtCurrentPoint));
}
auto pqTop = *pq.rbegin();
if(ongoingHeight != pqTop){
ongoingHeight = pqTop;
ans.push_back({currentPoint, ongoingHeight});
}
}
return ans;
}
int main() {
int n;
cin >> n;
vector<vector<int>> buildings(n, vector<int>(3));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
cin >> buildings[i][j];
}
}
vector<vector<int>> result = getSkyline(buildings);
for (auto &p : result) {
cout << p[0]<<p[1]<< endl;
}
}
Skyline โ
#include <bits/stdc++.h>
using namespace std;
void minimumBribes(vector<int> A)
{
int n = A.size();
int cnt = 0;
for(int i = n - 1; i >= 0; i--)
{
if(A[i] != (i + 1))
{
if(((i - 1) >= 0) && A[i - 1] == (i + 1))
{
cnt++;
swap(A[i], A[i-1]);
}
else if(((i - 2) >= 0) && A[i - 2] == (i + 1))
{
cnt += 2;
A[i - 2] = A[i - 1];
A[i - 1] = A[i];
A[i] = i + 1;
}
else
{
cout << "Too chaotic" << endl;
return;
}
}
}
cout << cnt << endl;
return;
}
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
vector<int> A(n);
for (int j = 0; j < n; j++) {
cin >> A[j];
}
minimumBribes(A);
}
return 0;
}
Min bribes โ
using namespace std;
void minimumBribes(vector<int> A)
{
int n = A.size();
int cnt = 0;
for(int i = n - 1; i >= 0; i--)
{
if(A[i] != (i + 1))
{
if(((i - 1) >= 0) && A[i - 1] == (i + 1))
{
cnt++;
swap(A[i], A[i-1]);
}
else if(((i - 2) >= 0) && A[i - 2] == (i + 1))
{
cnt += 2;
A[i - 2] = A[i - 1];
A[i - 1] = A[i];
A[i] = i + 1;
}
else
{
cout << "Too chaotic" << endl;
return;
}
}
}
cout << cnt << endl;
return;
}
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
vector<int> A(n);
for (int j = 0; j < n; j++) {
cin >> A[j];
}
minimumBribes(A);
}
return 0;
}
Min bribes โ
#include<bits/stdc+.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
int next_greater[n], next_smaller[n];
stack<int> s1;
for ( int i=n-1; i>=0; i--)
{
while (!s1.empty() && a[s1.top()] <= a[i] )
s1.pop();
if (!s1.empty())
next_greater[i] = s1.top();
else
next_greater[i] = -1;
s1.push(i);
}
stack<int> s2;
for (int i=n-1; i>=0; i--)
{
while (!s2.empty() && a[s2.top()] >= a[i])
s2.pop();
if (!s2.empty())
next_smaller[i] = s2.top();
else
next_smaller[i] = -1;
s2.push(i);
}
for (int i=0; i< n; i++)
{
if (next_greater[i] != -1 && next_smaller[next_greater[i]] != -1)
cout << a[next_smaller[next_greater[i]]] <<" ";
else
cout<<-1<<" ";
}
}
Number games โ
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
int next_greater[n], next_smaller[n];
stack<int> s1;
for ( int i=n-1; i>=0; i--)
{
while (!s1.empty() && a[s1.top()] <= a[i] )
s1.pop();
if (!s1.empty())
next_greater[i] = s1.top();
else
next_greater[i] = -1;
s1.push(i);
}
stack<int> s2;
for (int i=n-1; i>=0; i--)
{
while (!s2.empty() && a[s2.top()] >= a[i])
s2.pop();
if (!s2.empty())
next_smaller[i] = s2.top();
else
next_smaller[i] = -1;
s2.push(i);
}
for (int i=0; i< n; i++)
{
if (next_greater[i] != -1 && next_smaller[next_greater[i]] != -1)
cout << a[next_smaller[next_greater[i]]] <<" ";
else
cout<<-1<<" ";
}
}
Number games โ
public static int findBestPath(int n, int m, int max_t, List beauty, List u, List v, List t) {
// Write your code here
createGraph(n, m, u, v, t);
// int twoWay = dfs(0, beauty, max_t);
// visited = new HashSet<>();
// cycle(0, beauty, max_t, beauty.get(0), 0);
visited.add(0);
dfs2(0, beauty, max_t, beauty.get(0));
return totalAns;
}
static int totalAns = Integer.MIN_VALUE;
public static void dfs2(int node, List beauty, int maxT, int sum) {
if (node == 0) {
totalAns = Math.max(totalAns, sum);
}
for (int nbr : map.get(node).keySet()) {
int time = map.get(node).get(nbr);
if (time <= maxT) {
if (!visited.contains(nbr)) {
visited.add(nbr);
dfs2(nbr, beauty, maxT - time, sum + beauty.get(nbr));
visited.remove(nbr);
} else
dfs2(nbr, beauty, maxT - time, sum);
}
}
}
static HashSet<Integer> visited = new HashSet<>();
static HashMap<Integer, HashMap<Integer, Integer>> map = new HashMap<>();
public static void createGraph(int n, int m, List u, List v, List t) {
for (int i = 0; i < n; ++i) {
map.put(i, new HashMap<>());
}
for (int i = 0; i < m; ++i) {
int x = u.get(i);
int y = v.get(i);
int z = t.get(i);
map.get(x).put(y, z);
map.get(y).put(x, z);
}
}
Find best path
Linkedln โ
// Write your code here
createGraph(n, m, u, v, t);
// int twoWay = dfs(0, beauty, max_t);
// visited = new HashSet<>();
// cycle(0, beauty, max_t, beauty.get(0), 0);
visited.add(0);
dfs2(0, beauty, max_t, beauty.get(0));
return totalAns;
}
static int totalAns = Integer.MIN_VALUE;
public static void dfs2(int node, List beauty, int maxT, int sum) {
if (node == 0) {
totalAns = Math.max(totalAns, sum);
}
for (int nbr : map.get(node).keySet()) {
int time = map.get(node).get(nbr);
if (time <= maxT) {
if (!visited.contains(nbr)) {
visited.add(nbr);
dfs2(nbr, beauty, maxT - time, sum + beauty.get(nbr));
visited.remove(nbr);
} else
dfs2(nbr, beauty, maxT - time, sum);
}
}
}
static HashSet<Integer> visited = new HashSet<>();
static HashMap<Integer, HashMap<Integer, Integer>> map = new HashMap<>();
public static void createGraph(int n, int m, List u, List v, List t) {
for (int i = 0; i < n; ++i) {
map.put(i, new HashMap<>());
}
for (int i = 0; i < m; ++i) {
int x = u.get(i);
int y = v.get(i);
int z = t.get(i);
map.get(x).put(y, z);
map.get(y).put(x, z);
}
}
Find best path
Linkedln โ
int getMinimumCost(vector<int> arr)
{
long long maxDiff = 0 ;
int index = -1 ;
for(int i= 0 ; i < arr.size()-1 ; i++)
{
if(abs(arr[i]-arr[i+1]) > maxDiff)
{
maxDiff = abs(arr[i]-arr[i+1]) ;
index = i ;
}
}
int median = (arr[index] + arr[index+1]) / 2 ;
long long initialCost = 0 ;
for(int i= 0 ; i < arr.size()-1 ; i++)
initialCost += pow(arr[i]-arr[i+1],2) ;
initialCost = initialCost + pow(arr[index] - median,2) + pow(median - arr[index+1],2) - pow(arr[index] - arr[index+1] ,2) ;
return initialCost ;
}
Linkedln โ
{
long long maxDiff = 0 ;
int index = -1 ;
for(int i= 0 ; i < arr.size()-1 ; i++)
{
if(abs(arr[i]-arr[i+1]) > maxDiff)
{
maxDiff = abs(arr[i]-arr[i+1]) ;
index = i ;
}
}
int median = (arr[index] + arr[index+1]) / 2 ;
long long initialCost = 0 ;
for(int i= 0 ; i < arr.size()-1 ; i++)
initialCost += pow(arr[i]-arr[i+1],2) ;
initialCost = initialCost + pow(arr[index] - median,2) + pow(median - arr[index+1],2) - pow(arr[index] - arr[index+1] ,2) ;
return initialCost ;
}
Linkedln โ
Tomorrow Anyone Give Exam IBM OA?
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
DE SHAW hiring Ascend Educare is a six-month mentorship program for women in technology
Eligibility Criteria:
Second/third-year student in a BTech/BE program
Third/fourth-year student in a five-year dual degree program (BTech + MTech, BE + ME)
First-year student in a two-year MTech/MS/MCA program
Second-year student in a three-year MCA program;
https://www.deshawindia.com/forms/REQ5Qjg1RTktM0Q5NC00QjhFLTkyNDYtNTE1OENENjE5QjhB
Eligibility Criteria:
Second/third-year student in a BTech/BE program
Third/fourth-year student in a five-year dual degree program (BTech + MTech, BE + ME)
First-year student in a two-year MTech/MS/MCA program
Second-year student in a three-year MCA program;
https://www.deshawindia.com/forms/REQ5Qjg1RTktM0Q5NC00QjhFLTkyNDYtNTE1OENENjE5QjhB
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name: Amazon Dublin
Role: SDE Internship
Batch: 2024 and 2025 passouts
Location: Dublin
Apply: https://bit.ly/3qqKNyi
Role: SDE Internship
Batch: 2024 and 2025 passouts
Location: Dublin
Apply: https://bit.ly/3qqKNyi
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name : FRND
Role : SDE Internship ( Python )
Batch : 2023/2024 pass-outs
Link : https://www.linkedin.com/jobs/view/3687648587
Role : SDE Internship ( Python )
Batch : 2023/2024 pass-outs
Link : https://www.linkedin.com/jobs/view/3687648587
Linkedin
12,000+ Python Developer jobs in India (233 new)
Todayโs top 12,000+ Python Developer jobs in India. Leverage your professional network, and get hired. New Python Developer jobs added daily.
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name: Emitrr
Role: SDE Intern
Batch eligible: 2023 and 2024 grads
Apply: https://www.linkedin.com/jobs/view/3685493923
Role: SDE Intern
Batch eligible: 2023 and 2024 grads
Apply: https://www.linkedin.com/jobs/view/3685493923
Linkedin
29 Software Engineer Intern jobs in India (4 new)
Todayโs top 29 Software Engineer Intern jobs in India. Leverage your professional network, and get hired. New Software Engineer Intern jobs added daily.
Software Engineer Swaraj Kumar is offering a group session to help you ace the FAANG interviews and to answer your questions and doubts directly ๐ฏ
Heโll be sharing the following:
- Experience and insights on the interview process
- How to enhance your skill set
- Tips to grab high-paying job opportunities
- Ways to build your resume.
Register now - https://visit.preplaced.in/n8u
The session will also include a live Q&A, where the mentor will answer all your doubts and concerns:)
Don't miss out!
Heโll be sharing the following:
- Experience and insights on the interview process
- How to enhance your skill set
- Tips to grab high-paying job opportunities
- Ways to build your resume.
Register now - https://visit.preplaced.in/n8u
The session will also include a live Q&A, where the mentor will answer all your doubts and concerns:)
Don't miss out!
app.preplaced.in
Live Events | Preplaced
1:1 LIVE group mentorship sessions by top Preplaced mentors | Book a long-term mentorship program at Preplaced | Become a part of mentor guided career journey
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name: Baker Hughes
Role: Software Engineer
Batch eligible: 2021, 2022 and 2023 grads
Apply: https://bit.ly/45p1qJq
Role: Software Engineer
Batch eligible: 2021, 2022 and 2023 grads
Apply: https://bit.ly/45p1qJq