Juspay most prob ques
Juspay most prob ques
Problem Statement: Select minimum blood units to ensure Stephan's power exceeds Damon's
remaining total
Coin Game
Problem Statement: Find minimum star ng capital to avoid nega ve balance
Problem Recap
Given train mings and routes (i.e., a weighted graph), find the most efficient route and travel
me between two sta ons.
OR
A. Find the minimum fare between two sta ons with transfer limits.
B. Modify Dijkstra to handle me-dependent edge weights (e.g., peak/off-peak
mings).
C. Find the fastest route if some routes are temporarily closed (remove edges and
rerun).
#include <iostream>
#include <vector>
#include <queue>
#include <limits>
using namespace std;
while (!pq.empty()) {
int cost = pq.top().first;
int u = pq.top().second;
pq.pop();
// Example usage
int main() {
int n = 5; // number of sta ons
vector<vector<pii>> graph(n);
// Add edges: graph[u].push_back({v, weight});
graph[0].push_back({1, 10});
graph[0].push_back({2, 5});
graph[1].push_back({2, 2});
graph[1].push_back({3, 1});
graph[2].push_back({1, 3});
graph[2].push_back({3, 9});
graph[2].push_back({4, 2});
graph[3].push_back({4, 4});
graph[4].push_back({3, 6});
graph[4].push_back({0, 7});
------------------------------------------------------------------------------------------------------------------------------
Problem Recap
If 5 rickshaws serve 20 passengers per hour each, how many rickshaws are needed to serve
200 passengers in 2 hours?
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int passengers = 200, hours = 2, perRickshawPerHour = 20;
int perRickshawTotal = perRickshawPerHour * hours;
int rickshaws = (passengers + perRickshawTotal - 1) / perRickshawTotal; // ceil division
cout << "Rickshaws needed: " << rickshaws << endl;
return 0;
}
Problem Recap
A number has digits in the ra o 2:3:4. If the sum of its digits is 81, what is the number?
#include <iostream>
using namespace std;
int main() {
int sum = 81;
int x = sum / 9;
int d1 = 2 * x, d2 = 3 * x, d3 = 4 * x;
cout << "The number is: " << d1 << d2 << d3 << endl; // Concatena on
return 0;
}
Problem:
Find the shortest path between two sta ons but with a maximum allowed number of
transfers (edges).
#include <bits/stdc++.h>
using namespace std;
struct State {
int node, dist, transfers;
};
while(!q.empty()) {
auto [u, d, t] = q.front(); q.pop();
if (u == dest) return d;
#include <bits/stdc++.h>
using namespace std;
while (!q.empty()) {
int u = q.front(); q.pop();
for (int v : graph[u]) {
if (dist[v] == INT_MAX) {
dist[v] = dist[u] + 1;
q.push(v);
}
}
}
return dist;
}
while(!pq.empty()) {
int u = pq.top().second;
int w = pq.top().first;
pq.pop();
Given a directed graph and a star ng node, find the maximum weight among all nodes
reachable from the start.
#include <bits/stdc++.h>
using namespace std;
Given a directed graph where each node has a weight, find the cycle with the largest sum of
node weights. If no cycle exists, return -1.
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
DSA Solu on: Maximum Input Point (Farthest Common Reachable Node)
#include <bits/stdc++.h>
using namespace std;