I had Participated in Cashfree Frontend Intern on mid of june had my OA scheduled and was asked 5 on Error codes , linkedList ,user experience and graph
later I had 3 question 2 dsa question and 1 node.js (javascript Q)
Q1 dsa 2432. The Employee That Worked on the Longest Taskhttps://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/description/
You are given a binary array arr of length n, consisting only of 0s and 1s.
You are allowed to choose exactly one subarray (possibly empty) and flip all of its elements — that is, convert all 0s in the subarray to 1s, and all 1s to 0s.
Your task is to determine how many distinct values for the total number of 1s in the array can be obtained after performing exactly one flip operation.
int getDistinctOneCounts(vector<int> arr);arr: A vector of n integers, where each element is either 0 or 1.
Constraints:
arr is either 0 or 1.arr = [0, 1, 1, 0]4Possible flips and resulting 1-counts:
| Subarray Chosen (0-based indices) | Flipped Array | Number of 1s |
|---|---|---|
| None (empty subarray) | [0, 1, 1, 0] | 2 |
| [0, 0] | [1, 1, 1, 0] | 3 |
| [1, 2] | [0, 0, 1, 0] | 1 |
| [0, 3] | [1, 0, 0, 1] | 2 |
| [0, 1] | [1, 0, 1, 0] | 2 |
| [2, 3] | [0, 1, 0, 1] | 2 |
| [1, 3] | [0, 0, 0, 1] | 1 |
| [0, 2] | [1, 0, 0, 0] | 1 |
| [1, 2] | [0, 0, 0, 0] | 0 |
The distinct counts of 1s after these flips are: {0, 1, 2, 3} → total 4 distinct values.
You are building a custom auction system with unique bidding rules:
updatePrice, but only if their bid is higher than the current bid.callBid with a valid offer.callBid, no further bids or claims are allowed on it.You need to implement the following three functions to manage the auction process:
startAuction(auctions, entity, startingPrice)Starts an auction for a given item.
Parameters:
auctions (object): A shared object that stores all auctions.entity (string): The name of the item.startingPrice (number): The minimum price to start the auction.Returns: Nothing (updates the auctions object).
updatePrice(auctions, entity, bidPrice)Places a new bid for the item.
A new bid is only accepted if it is greater than both the starting price and the current highest bid.
Bids are ignored if the item has already been claimed.
Parameters:
auctions (object): The shared auction data.entity (string): The item being bid on.bidPrice (number): The new bid price.Returns: Nothing (updates the bid in auctions).
callBid(auctions, entity, callPrice)Attempts to claim the item with a final offer.
If the item is unclaimed and the callPrice is greater than or equal to the current bid, the call is "successful" and the item is marked as sold.
Otherwise, the call is "unsuccessful".
Parameters:
auctions (object): The shared auction data.entity (string): The item to claim.callPrice (number): The price the bidder wants to claim the item at.Returns: "successful" or "unsuccessful"
Input
startAuction vase 100
updatePrice vase 150
updatePrice vase 200
callBid vase 210Output
successfulExplanation:
vase starts at 100.Input
startAuction car 5000
callBid car 4500
callBid car 5000Output
unsuccessful
successfulExplanation:
callBid of 4500 is below starting price — rejected.callBid of 5000 is equal to starting price — accepted.1 ≤ length ≤ 100).1 ≤ startingPrice, bidPrice, callPrice ≤ 10^5.function startAuction(auctions, entity, startingPrice) {
auctions[entity] = {
startingPrice,
highestBid: null,
isClaimed: false
};
}
function updatePrice(auctions, entity, bidPrice) {
const auction = auctions[entity];
if (!auction || auction.isClaimed) return;
const current = auction.highestBid ?? auction.startingPrice;
if (bidPrice > current) {
auction.highestBid = bidPrice;
}
}
function callBid(auctions, entity, callPrice) {
const auction = auctions[entity];
if (!auction || auction.isClaimed) return "unsuccessful";
const current = auction.highestBid ?? auction.startingPrice;
if (callPrice >= current) {
auction.isClaimed = true;
return "successful";
}
return "unsuccessful";
}