⏱ 0:01est. 25 min
Cimpress
/**
* - The first round went with a medium level DSA question followed by Javascript questions and my previous experience related details.
* - Next round was the design round where they asked to Design the restaurant system where all waiters are replaced by robots.
* - Designed the cart and method to get net price with if-else. The interviewer asked me then to use a design pattern so I updated it to use different classes for coupons.
* - Designed the solution using client and server module where the client is running in Robots and server is running in the central server.
Design the restaurant system where all waiters are replaced by robots. solution using client and server module where the client is running in Robots and server is running in the central server.
- Shopping cart, Robo Restaurant etc.
- Write classes for a shopping cart with specific rules (to check algorithm and design patterns)
- Design a restaurant which has robot waiters... (to check solution design)
- They informed me that the process takes 5 rounds
1. Design round (to check algorithm and design patterns)
2. Another design round ( to check solution design)
3. Technical round (as they call it but it's not so technical)
4. Another technical round
5. HR/Managerial round
- In the first round they asked me to design a shopping cart with products and coupons and calculate the net price after applying coupons on products. Coupons can be of diffent types with certain conditions.
-- Designed the cart and method to get net price with if-else. The interviewer asked me then to use a design pattern so I updated it to use different classes for coupons.
- In the second round, they asked me to design a solution approach for a restaurant management system where robots are using the software. Their expectation was to design the system which can be leveraged by robots to check available tables, book table, place order, serve order etc.
-- Designed the solution using client and server module where the client is running in Robots and server is running in the central server.
- One question API Documentation, single question of GraphQL(what is fragment), single question from JS. All questions were like a GK questions.
- Design a cart with discount structure of % basis, fixed amount etc... No chance you can clarify if he wanted to design API or data structures or frontend components etc.. Interviewer just said design whatever you like - you just can't hit the goal without specific clarity in entire solution.
- Number of identical pairs of numbers in an array, with complexity n log n
- 2nd shopping cart design with multiple coupon types in a sequence
- .Model a train signal for 2 tracks.
- Before you actually go to the face-to-face interview, HR calls you again to talk about the interview. And then finally on this day they'll do a design test (class design, stacktrace of code, ask some changes to implement and use cases), then a code challenge (again) for you to implement some calculations of a shopping cart and discount vouchers to price.
- Design a system that uses robots as waiters in a restaurant
- Describe the class design I would use for S, M, L shirts and shorts.
- How do you design a Restaurant Robot using object oriented programming? Design appropriate class and state diagram.
I drew few class with inheritance and model objects. explained it and that's pretty much it.
I think 3 design patterns will be used:
1. Observer: Robot subscribes to user's commands, also when meal is ready.
2. Factory Method: Robot provides separate interface to user, and prepares meal with help of separate class at backend.
3. Command: Takes command to edit menu. Add item, remove item et
- Algorithm for restaurant operation
- How many bottles of shampoo should be produced for usage by hotels?
- Think about various conditions - validity of bottles, bald people, people using soaps, N star hotels, how many times could be a bottle used...
* */
// https://codeshare.io/VN9RR9
Web sites like Vistaprint and Amazon have an online shopping cart that holds the customer's order. Your goal is to write a program that calculates the total price of the order in the cart. The catch is that the cart may contain coupons that affect the prices. There are three kinds of coupons:
* Take N% off each individual product in the cart
- For example, a general "10% off" coupon - 10_OFF
* Take P% off the next product in the cart - N_OFF_NEXT
- For example, take 20% off your next product -
* Take $D off of the Nth product of type T - FIXED_OFF_ON_N_PRODUCT
- For example, take $5 off your third business card holder
== Example #1 ==
* Coupon: Take 10% off the next product in the cart
* $10 postcard sorter
* $20 stationery organizer
The coupon is applied to the postcard sorter, and the cart total is $29.
== Example #2 ==
* $10 postcard sorter
* Coupon: Take 10% off the next product in the cart
* $20 stationery organizer
The cart total here is $28.
== Example #3 ==
* $10 postcard sorter
* Coupon: Take $2 off your 2nd postcard sorter
* Coupon: 25% off each individual item
* Coupon: Take 10% off the next item in the cart
* $10 postcard sorter
Total = ($10 * 75%) + (($10 - $2) * 75% * 90%) = $7.50 + $5.40 = $12.90
---
Coupon rules:
If multiple coupons of different types could apply to a single product, apply all the discounts in the sequence they were presented.
Write a program that, given the sequence of products in the shopping cart, computes their total price. Items in the order, including both products and coupons, must be considered in sequence.
You are responsible only for writing the class definitions for necessary components, such as "Cart". No UI, no input reading.
Write the method Cart.TotalPrice(), implemented in terms of your classes.
function Product (name,price,quantity) {
this.name = name
this.price = price
this.quantity = quantity;
}
const intitalState = {
cart_products: [],
coupons: [],
}
function reducer(state, action) {
switch(action.type) {
case actionTypes.ADD_PRODUCT:
return {
...state.products,
action.payload,
}
case actionTypes.ADD_COUPON:
const updatedProducts = state.products.map((product) => {
action.payload.applyCoupon(action.payload.type, product, products);
})
return {
products: [...updatedProducts],
...state.coupons,
action.payload,
}
}
}
function CouponStrategy (percentage) {
this.percentatge = percentatge;
}
CouponStrategy.prototype.applyCoupon = (type, products) => {
if(!this.applyCoupon) {
throw new Error("Apply coupon should be implemented");
}
}
function PercentageOffStrategy () {}
PercentageOffStrategy.prototype = Object.create({}, CouponStrategy);
PercentageOffStrategy.prototype.applyCoupon = (type, products) => {
if type==''
return price - price*(this.percentage/100);
}
function PercentageOffNextStrategy () {}
PercentageOffNextStrategy.prototype = Object.create({}, PercentageOffStrategy);
function FixedPriceOffStrategy (price) {
this.price = price;
}
FixedPriceOffStrategy.prototype = Object.create({}, CouponStrategy);
FixedPriceOffStrategy.prototype.applyCoupon = (type, products) => {
type == 'type'
return price - this.price;
}
const ShoppingContext = React.createContext();
const Provider = ({chilren}) => {
const [state, dipatch] = React.useReducer(reducer, intialState);
const value = {
addProduct: (product) => {
dispatch({
type: actionTypes.ADD_PRODUCT,
payload: product
})
},
addCoupon: (product) => {
dispatch({
type: actionTypes.ADD_COUPON,
payload: coupon
}),
getTotalPrice: () => {
const total = state.products.reduce((acc, product)=> {
acc += product.price;
},0)
return state.total
}
}
return <ShoppingContext.Provider value={value}>
{chilren}
</ShoppingContext.Provider>
}
interfact Coupon {
type: xx|y|z,
amount: 10,
productNumber: number
applyCoupon: function
}
class Child extends Coupon {
applyCoupon
}
function ShoppingCart() {
const {addProduct, addCoupon, getTotalPrice} = React.useContext(ShoppingContext)
const laptop = new Product('laptopX', 100, 1)
addProduct(laptop)
addCoupon({
10,
type: '10_OFF'
})
addCoupon({
20,
type: 'N_OFF_NEXT'
productNumber: 0,
})
addCoupon({
20,
type: 'FIXED_OFF_ON_N_PRODUCT',
productNumber: 3,
})
addCoupon({
10,
type: 'NEXT_ITEM'
})
addCoupon()
cosnt total = getTotalPrice();
return total;
}
*/
/** Round 2
Welcome to Pair Interview !
# Tic Tac Toe
- The game is played on a grid that's 3 by 3 squares
- Players alternate placing X’s and O’s in empty squares
- X always plays first
- Players cannot play on a played square
- A Player wins when it has three squares in a row
- Horizontally
- Vertically
- Diagonally
- If all nine squares are filled and neither player has won, the game is a draw
LLD
- Class
- Entities
- Players
- GameBoard
- Game
import React from "react";
import "./styles.css";
const Game = ({ gameMatrix, players, n }) => {
const [winner, setWinner] = React.useState(null);
const [matrix, setMatrix] = React.useState(gameMatrix);
const [currentPlayer, setCurrentPlayer] = React.useState(players[0]);
const playerHasWon = (rowIndex, colIndex) => {
console.log("n", n);
// down
// [
// [1,2,3], 0
// [4,5,6], 1
// [7,8,9], 2
// ]
let hasWon = false;
const response = matrix.forEach((row) => {
if (hasWon) {
return;
}
hasWon =
row.filter((r) => {
console.log("r", r);
return r === currentPlayer.symbol;
}).length === n;
});
console.log("hasWon", hasWon);
return hasWon;
console.log("response", response);
// if (_rowIndex == rowIndex) {
// return (areSame =
// row.filter((r) => r === currentPlayer.symbol).length == n);
// }
// });
// upward
// right
/// left
// diagonal
return false;
};
const move = (rowIndex, colIndex) => {
// check if the cell is empty
if (matrix[rowIndex][colIndex] !== "-1") {
throw new Error("Invalid move");
}
// fill the cell
const newMatrix = [...matrix];
newMatrix[rowIndex][colIndex] = currentPlayer.symbol;
setMatrix(newMatrix);
// check if the player has won
if (playerHasWon(rowIndex, colIndex)) {
setWinner(currentPlayer);
return;
}
// switch players
setCurrentPlayer((prevState) =>
prevState.id === 1 ? players[1] : players[0]
);
};
console.log("matrix", matrix);
return (
<div>
{!!winner ? (
<h1>{winner?.id} wins</h1>
) : (
<div>
{matrix &&
matrix.map((row, rowIndex) => (
<span key={rowIndex} className="row">
{row.map((item, colIndex) => (
<span
key={`${colIndex}_${rowIndex}`}
className="col"
onClick={() => move(rowIndex, colIndex)}
>
{matrix[rowIndex][colIndex]}
</span>
))}
</span>
))}
</div>
)}
</div>
);
};
export default function App() {
// 3x3
const n = 3;
const matrix = Array(n)
.fill("-1")
.map((_) => Array(n).fill("-1"));
console.log(matrix);
const playerTypes = {
X: "X",
O: "O",
};
const players = [
{
id: 1,
symbol: playerTypes.X,
},
{
id: 2,
symbol: playerTypes.O,
},
];
// Game
// Board
// Player (2)
// enum: 'X' | 'O'
// Move: () => {
// isValid? -- is the box empty||null
// if yes
// return the winner
// else
// update matrix
// }
return (
<div className="App">
<h1>Tic Tac Toe</h1>
<div className="game">
<Game gameMatrix={matrix} players={players} n={n} />
</div>
</div>
);
}
.App {
font-family: sans-serif;
text-align: center;
}
.game {
display: flex;
align-items: center;
justify-content: center;
}
.row {
display: flex;
flex-direction: row;
}
.col {
display: flex;
flex-direction: column;
border: 1px solid black;
padding: 10px;
}
*/