Square Yards Interview
Summary
I interviewed for a MERN Stack Developer role at Square Yards, where I was asked several logical brain teasers, React component tasks, Node.js concepts, and system design questions.
Full Experience
Company: Square Yards Role: MERN Stack Developer Experience: 6 Years Stack: React.js + Node.js + Express.js + MongoDB Hiring: Naukri Job Posting Salary: 25LPA+
Logical Questions A bat and a ball cost ₹110 together. The bat costs ₹100 more than the ball. How much does the ball cost? Answer : ₹5 (bat ₹105)
You have ₹100. You spend ₹70, then get ₹50 back, then spend ₹60. How much money do you have? Answer: 20
React Js Create a counter Requirements Increment Decrement Reset Show the last 5 counter values
Copy Color to an Empty Box Build a React component that displays 4 boxes: 3 colored boxes (e.g., Red, Green, Blue) 1 empty white box Requirements Clicking on one of the colored boxes should copy its color. This is the first click. The selected color should be stored in state, but the white box should remain unchanged. Clicking on the white box should paste the copied color into it. This is the second click. The white box should change to the copied color. The interaction should require exactly two clicks: First click → Select (copy) a color. Second click → Apply (paste) the copied color to the white box.
Create a Stopwatch Requirements Start Pause Reset
Sort Users You are given the following array of users: const users = [ { id: 1, name: "John", age: 30 }, { id: 2, name: "Mike", age: 20 }, { id: 3, name: "Alex", age: 25 }, { id: 4, name: "Sarah", age: 28 }, { id: 5, name: "Emma", age: 22 } ];
Requirements Build a React component that displays the list of users in a table Provide the following functionality: Sort by Name (A–Z) When the "Sort by Name" button is clicked, users should be sorted alphabetically by their name. Sort by Age (Ascending) When the "Sort by Age" button is clicked, users should be sorted from youngest to oldest. The UI should update immediately after sorting.
Q: How do you decide what should be local state and what should be global state? Q: How would you prevent duplicate API requests?
Node.js How does Node.js handle multiple concurrent requests if it runs on a single thread? Expected topics Event Loop Non-blocking I/O libuv Worker threads OS thread pool
When would Node.js become slow? CPU intensive work Infinite loops Huge JSON parsing Synchronous filesystem calls Large regex
Print numbers 1 to 5 with 1-second delay between each async function printNumbers() { for (let i = 1; i <= 5; i++) { await new Promise(resolve => setTimeout(resolve, 1000)); console.log(i); } } printNumbers();
Create a simple Express middleware to log request time
function requestLogger(req, res, next) {
const start = Date.now();
res.on("finish", () => {
console.log(${req.method} ${req.url} - ${Date.now() - start}ms);
});
next();
}
Count word frequency in a string
How would you design a high-throughput notification service (Email, SMS, WhatsApp)?
How would you optimize an API handling 10,000 requests per second?
A MongoDB collection has 100 million documents. Queries have become slow. What would you do?
How do you ensure messages are not processed twice in Kafka?
Design a rate limiter for an API.
Design a file upload service supporting files up to 10 GB.
Database architecture to show customer chat history like ChatGpt shows.
Interview Questions (20)
Bat and Ball Price Puzzle
A bat and a ball cost ₹110 together. The bat costs ₹100 more than the ball. How much does the ball cost?
Money Transaction Puzzle
You have ₹100. You spend ₹70, then get ₹50 back, then spend ₹60. How much money do you have?
React Counter Component
Create a counter component with the following requirements:
- Increment
- Decrement
- Reset
- Show the last 5 counter values
React Color Copy‑Paste Component
Build a React component that displays 4 boxes:
- 3 colored boxes (Red, Green, Blue)
- 1 empty white box Requirements:
- Clicking a colored box copies its color (first click).
- Store the selected color in state while the white box remains unchanged.
- Clicking the white box pastes the copied color (second click) and changes its background. The interaction must consist of exactly two clicks: copy then paste.
React Stopwatch
Create a stopwatch component with the following functionality:
- Start
- Pause
- Reset
React User Sort Component
Given an array of user objects, build a React component that displays the users in a table and provides two buttons:
- "Sort by Name" sorts users alphabetically (A‑Z).
- "Sort by Age" sorts users from youngest to oldest. The UI should update immediately after sorting.
Local vs Global State Decision
How do you decide what should be local state and what should be global state in a React application?
Prevent Duplicate API Requests
How would you prevent duplicate API requests in a frontend application?
Node.js Concurrency Handling
How does Node.js handle multiple concurrent requests if it runs on a single thread? Discuss the event loop, non‑blocking I/O, libuv, worker threads, and the OS thread pool.
Node.js Performance Bottlenecks
When would Node.js become slow? Consider CPU‑intensive work, infinite loops, huge JSON parsing, synchronous filesystem calls, and large regular expressions.
Async Print Numbers with Delay
Write an async function that prints numbers 1 to 5 with a 1‑second delay between each.
Express Request Logger Middleware
Create a simple Express middleware that logs the request method, URL, and response time.
Word Frequency Counter
Write a function that counts the frequency of each word in a given string.
High‑Throughput Notification Service Design
Design a high‑throughput notification service that can send Email, SMS, and WhatsApp messages.
API Optimization for 10,000 RPS
How would you optimize an API that needs to handle 10,000 requests per second?
MongoDB Performance Troubleshooting
A MongoDB collection has 100 million documents and queries have become slow. What steps would you take to improve performance?
Exactly‑Once Processing in Kafka
How do you ensure messages are not processed twice in Kafka?
API Rate Limiter Design
Design a rate limiter for an API.
Large File Upload Service Design
Design a file upload service that supports files up to 10 GB.
Chat History Database Architecture
Design a database architecture to store and retrieve customer chat history similar to the chat view in ChatGPT.