Amazon ML Summer School Previous Year Questions
The Amazon Machine Learning (ML) Summer School is a premier program aimed at equipping engineering students in India with industry-relevant ML skills. It promises an immersive learning experience led by Amazon’s top scientists. This blog covers what the program is, who can apply, how to apply, and what to expect.
Amazon ML Summer School Actual MCQ & Coding Questions
What is the Amazon ML Summer School?
This free four-weekend program blends theory and practice across key ML topics such as Supervised Learning, Deep Neural Networks, Generative AI, Reinforcement Learning, and more. Sessions include live lectures and Q&As with Amazon scientists.
Key Highlights:
- Curriculum: 8 modules covering ML topics including Generative AI, Causal Inference, and Reinforcement Learning.
- Schedule: Saturdays and Sundays, 9 AM–1 PM IST (sessions) and 2 PM–5 PM IST (Q&A).
- Networking: Includes access to Amazon Research Days (ARD) and mentorship from scientists.
- Internship Pathway: Top performers may be eligible for internships in Data Science or Applied Scientist roles at Amazon.
Over 17,500 students applied in 2022 alone—underscoring the program’s growing popularity.
Eligibility
- Who Can Apply: Engineering students enrolled in Bachelor’s, Master’s, or PhD programs at recognized Indian institutes.
- Graduation Year: Final year or pre-final year students.
- Background: All engineering disciplines welcome. Familiarity with Python and basic ML concepts is helpful but not mandatory.
Selection Process
Candidates take a 60-minute test assessing math and programming skills:
- Part A: 20 MCQs on probability, statistics, and linear algebra.
- Part B: 2 DSA programming problems (Python recommended).
Top 3,000 scorers will be selected for the program.
How to apply for Amazon ML Summer School- Check now
💻 Part A – Amazon ML Summer School MCQ Questions
Question 1: Variance Calculation
Given a dataset, calculate the variance of the numbers: [2, 4, 6, 8, 10].
a) 4
b) 6
c) 8
d) 10
Show Answer
Answer: c) 8
Explanation: To calculate variance:
- Find the mean: (2+4+6+8+10)/5 = 30/5 = 6
- Calculate squared deviations from mean: (2-6)² + (4-6)² + (6-6)² + (8-6)² + (10-6)² = 16 + 4 + 0 + 4 + 16 = 40
- Divide by n: 40/5 = 8
Question 2: Matrix Eigenvalues
The eigenvalues of a 4x4 square matrix having 0's as the diagonal elements and 1's on the off diagonal elements is:
a) 2, -2, 0, 0
b) 1, -1, 1, -1
c) 3, -1, -1, -1
d) 4, 0, 0, 0
Show Answer
Answer: c) 3, -1, -1, -1
Explanation: The matrix is J - I where J is the all-ones 4×4 matrix and I is the identity matrix. The eigenvalues of the all-ones matrix J are: n=4 (with multiplicity 1) and 0 (with multiplicity 3). For J - I, the eigenvalues become: 4-1=3, 0-1=-1, 0-1=-1, 0-1=-1.
Question 3: Probability (Two-Headed Coin)
You pick a coin at random from a bag containing a fair coin and a two-headed coin. You flip the coin twice and get heads both times. What is the probability that you picked the fair coin?
a) 1/3
b) 4/13
c) 1/5
d) 2/5
Show Answer
Answer: c) 1/5
Explanation: Using Bayes' theorem: P(Fair|HH) = P(HH|Fair) × P(Fair) / P(HH)
- P(HH|Fair) = 1/4, P(HH|Two-headed) = 1
- P(Fair) = P(Two-headed) = 1/2
- P(HH) = P(HH|Fair) × P(Fair) + P(HH|Two-headed) × P(Two-headed) = (1/4)(1/2) + (1)(1/2) = 1/8 + 1/2 = 5/8
- P(Fair|HH) = (1/4)(1/2) / (5/8) = (1/8) / (5/8) = 1/5
Question 4: Medical Screening P-Value
In medical screening, it is sometimes more important to avoid false negatives than false positives. How would this affect the p-value we might use for a medical test?
a) we would choose a higher p-value
b) we would choose a lower p-value
c) we would choose the same p-value
d) false negatives do not depend on p-value
Show Answer
Answer: a) we would choose a higher p-value
Explanation: To avoid false negatives (missing actual cases), we want high sensitivity. This means we're willing to accept more false positives (Type I error). A higher p-value threshold makes it easier to reject the null hypothesis, increasing sensitivity but also increasing Type I error rate.
Question 5: Derivative Calculation
Given y=x^x, what is dy/dx at x = 2?
a) 4(1+log2)
b) 4(2+log2)
c) 4
d) 8
Show Answer
Answer: a) 4(1+log2)
Explanation: For y = x^x, use logarithmic differentiation:
- ln(y) = x ln(x)
- Differentiating: (1/y)(dy/dx) = ln(x) + 1
- Therefore: dy/dx = x^x(ln(x) + 1)
- At x = 2: dy/dx = 2^2(ln(2) + 1) = 4(ln(2) + 1) = 4(1 + log2)
Question 6: Algorithm Selection (Clustering)
In a scenario where you need to group customers based on purchasing behavior without prior labels, which algorithm should you use?
a) Linear regression
b) K-means clustering
c) Logistic regression
d) Random forest
Show Answer
Answer: b) K-means clustering
Explanation: This is an unsupervised learning problem since there are no prior labels. K-means clustering is designed to group similar data points together without requiring labeled training data. Linear regression and logistic regression are supervised learning algorithms that need labeled data.
Question 7: Correlation Calculation
For random variables X and Y, we have Var(X)=1, Var(Y)=4, and Var(2X-3Y)=34, then the correlation between X and Y is:
a) 1/2
b) 1/4
c) 1/3
d) None of the above
Show Answer
Answer: b) 1/4
Explanation:
- Var(2X - 3Y) = 4Var(X) + 9Var(Y) - 12Cov(X,Y)
- 34 = 4(1) + 9(4) - 12Cov(X,Y)
- 34 = 4 + 36 - 12Cov(X,Y)
- 34 = 40 - 12Cov(X,Y)
- 12Cov(X,Y) = 6
- Cov(X,Y) = 1/2
- Correlation = Cov(X,Y)/√(Var(X)×Var(Y)) = (1/2)/√(1×4) = (1/2)/2 = 1/4
Question 8: Probability (Chessboard - Version 1)
Two squares are chosen at random on a chessboard. What is the probability that they have a side in common?
a) 8/13
b) 17/18
c) 5/13
d) 1/18
Show Answer
Answer: d) 1/18
Explanation:
- Total ways to choose 2 squares from 64: C(64,2) = 2016
- Adjacent pairs: 4 corner squares (2 neighbors each) + 24 edge squares (3 neighbors each) + 36 interior squares (4 neighbors each)
- Total adjacent pairs = (4×2 + 24×3 + 36×4)/2 = 112
- Probability = 112/2016 = 1/18
Question 9: Gradient Descent vs Normal Equation
Suppose you have a dataset with m=50 examples and n=200000 features for each example. You want to use multivariate linear regression to fit the parameters Θ. Should you prefer gradient descent or the normal equation?
a) Gradient descent, since inverse(X^T X) will be very slow to compute
b) Gradient descent, since it will always converge to the optimal Θ
c) The normal equation, since it provides an efficient way to directly find the solution
d) The normal equation, since gradient descent might be unable to find the optimal Θ
Show Answer
Answer: a) Gradient descent, since inverse(X^T X) will be very slow to compute
Explanation: With n=200000 features, computing (X^T X)^(-1) requires O(n³) operations, which is computationally expensive. Gradient descent scales much better with the number of features and is preferred for high-dimensional problems. The normal equation becomes impractical when n is very large.
Question 10: Unbiased Estimators
Let M and S² be the mean and variance of a random sample of size > 1 from a normal population with unknown mean μ and unknown finite variance σ²>0. Which statements are true?
- S² is an unbiased estimator of σ², and S is an unbiased estimator of σ
- ((n-1)/n)M is an unbiased estimator of μ, and ((n-1)/n)S² is an unbiased estimator of σ²
a) 1 only
b) 2 only
c) Both 1 and 2
d) Neither 1 nor 2
Show Answer
Answer: d) Neither 1 nor 2
Explanation: Statement 1: S² (sample variance with n-1 denominator) is unbiased for σ², but S (sample standard deviation) is NOT unbiased for σ due to Jensen's inequality. Statement 2: M is unbiased for μ, but ((n-1)/n)M is biased. Also, ((n-1)/n)S² is biased for σ². Therefore, neither statement is completely true.
Question 11: Overfitting/Underfitting Detection
Given a graph of a model's training and validation error, determine if it represents underfitting or overfitting.
a) Underfitting
b) Overfitting
c) Neither
d) Both
Show Answer
Answer: Cannot be determined without the graph
Explanation: This question refers to a graph that is not provided in the document. To determine overfitting vs underfitting:
- Overfitting: Training error much lower than validation error
- Underfitting: Both training and validation errors are high and similar
Question 12: Probability (Biased Coins)
You have two coins. One is fair (1/2 heads probability) and the other is biased (3/4 heads probability). You randomly pick a coin and flip it twice, getting heads both times. What is the probability that you picked the fair coin?
a) 13/32
b) 4/13
c) 2/13
d) 19/32
Show Answer
Answer: b) 4/13
Explanation: Using Bayes' theorem:
- P(HH|fair) = (1/2)² = 1/4
- P(HH|biased) = (3/4)² = 9/16
- P(fair) = P(biased) = 1/2
- P(fair|HH) = P(HH|fair)×P(fair) / [P(HH|fair)×P(fair) + P(HH|biased)×P(biased)]
- = (1/4)(1/2) / [(1/4)(1/2) + (9/16)(1/2)] = (1/8) / (1/8 + 9/32) = (1/8) / (13/32) = 4/13
Question 13: Matrix Rank Relationships
If rank(A) is 2 and rank(AB) is 3, then:
a) rank(B) = 3
b) rank(B) <= 3
c) rank(B) >= 3
d) data insufficient
Show Answer
Answer: c) rank(B) >= 3
Explanation: We know that rank(AB) ≤ min(rank(A), rank(B)). Given rank(AB) = 3 and rank(A) = 2, this seems impossible under normal circumstances. However, if we interpret this as asking what must be true about rank(B), then since rank(AB) = 3, we must have rank(B) ≥ 3.
Question 14: System of Equations (Version 1)
The number of solutions for the system: 2x+y-z=4, x-2y+z=-2, -x+2y-z=-2 is:
a) 0
b) 1
c) Inf
d) Can't be determined
Show Answer
Answer: a) 0
Explanation: Looking at equations 2 and 3:
- x - 2y + z = -2
- -x + 2y - z = -2 Adding these equations: 0 = -4, which is a contradiction. Therefore, the system has no solutions.
Question 15: Logistic Classification Likelihood
When classifying data with logistic classification, what is the upper bound of the likelihood in the maximum likelihood method? Is this value attainable?
a) 1, Yes
b) e, No
c) 1, No
d) 0, Yes
Show Answer
Answer: a) 1, Yes
Explanation: The likelihood is the product of probabilities, each between 0 and 1. The maximum possible value is 1, achieved when all predictions are correct with probability 1. This is theoretically attainable when the data is perfectly separable.
Question 16: Neural Network Output Calculation
A 3-input neuron has weights 1, 4 and 3. The transfer function is linear with constant of proportionality = 3. The inputs are 4, 8 and 5 respectively. What will be the output?
a) 51
b) 153
c) 54
d) 160
Show Answer
Answer: b) 153
Explanation:
- Weighted sum = w₁x₁ + w₂x₂ + w₃x₃ = 1×4 + 4×8 + 3×5 = 4 + 32 + 15 = 51
- Output = transfer function × weighted sum = 3 × 51 = 153
Question 17: PCA Statements (Version 1)
Which statements about PCA are correct?
(i) We must standardize the data before applying
(ii) We should select principal components which explain the highest variance
(iii) We should select principal components which explain the lowest variance
(iv) We can use PCA for visualizing data in lower dimensions
a) (i), (ii) and (iv)
b) (ii) and (iv)
c) (iii) and (iv)
d) (i) and (iii)
Show Answer
Answer: b) (ii) and (iv)
Explanation:
- (i) False: Standardization is recommended but not always necessary
- (ii) True: We select components explaining the highest variance to retain most information
- (iii) False: We want high variance components, not low variance ones
- (iv) True: PCA is commonly used for dimensionality reduction and visualization
Question 18: Algorithm Selection (Regression)
Given a scenario involving a dataset with labeled data and a need to predict a continuous output, which algorithm is most suitable?
a) K-means clustering
b) Linear regression
c) Decision tree classifier
d) Support vector machine (SVM) with RBF kernel
Show Answer
Answer: b) Linear regression
Explanation: For predicting continuous output with labeled data, this is a supervised regression problem. Linear regression is specifically designed for predicting continuous values. K-means is unsupervised, decision tree classifier is for classification, and SVM with RBF can work but linear regression is more direct.
Question 19: Infinite Solutions Parameter
The system x + y + z = 1, ax - ay + 3z = 5, 5x - 3y + az = 6 has infinite solutions if a =?
a) -3
b) 3
c) -4
d) 4
Show Answer
Answer: d) 4
Explanation: For infinite solutions, the system must be consistent and the coefficient matrix must have rank less than the number of variables. This occurs when the equations become dependent, which happens when a = 4. This can be verified by setting up the augmented matrix and finding when rank(A) = rank([A|b]) < 3.
Question 20: Probability (Speed Trap - Version 1)
Police enforce speed limits on routes A, B, C, D operated 40%, 30%, 20%, 30% of time. Biff speeds with route probabilities 0.2, 0.1, 0.5, 0.2. What's the probability he gets a ticket?
a) 0.27
b) 0.93
c) 0.73
d) 0.07
Show Answer
Answer: a) 0.27
Explanation: P(ticket) = Σ P(route i) × P(enforcement on route i) = 0.2×0.4 + 0.1×0.3 + 0.5×0.2 + 0.2×0.3 = 0.08 + 0.03 + 0.10 + 0.06 = 0.27
Question 21: Matrix Eigenvalues (A^19)
Let A be a 2×2 matrix with a11=a12=a21=+1 and a22=-1. The eigenvalues of matrix A^19 are:
a) 1024 and -1024
b) 1024√2 and -1024√2
c) 4√2 and -4√2
d) 512√2 and -512√2
Show Answer
Answer: d) 512√2 and -512√2
Explanation:
- Matrix A = [1 1; 1 -1]
- Characteristic equation: det(A - λI) = (1-λ)(-1-λ) - 1 = λ² - 2 = 0
- Eigenvalues of A: λ₁ = √2, λ₂ = -√2
- Eigenvalues of A^19: (√2)^19 = 2^(19/2) = 2^9.5 = 512√2, (-√2)^19 = -512√2
Question 22: Characteristic Equation and Matrix Inverse
If the characteristic equation of matrix A is t²-t-1=0, then:
a) A^(-1) does not exist
b) A^(-1) exists but cannot be determined
c) A^(-1) = A - I
d) A^(-1) = A + I
Show Answer
Answer: c) A^(-1) = A - I
Explanation:
- From the characteristic equation: A² - A - I = 0
- Rearranging: A² = A + I
- Multiplying both sides by A^(-1): A = I + A^(-1)
- Therefore: A^(-1) = A - I
- Since 0 is not an eigenvalue (from t²-t-1=0), A^(-1) exists.
Question 23: Bias-Variance Tradeoff
Fitting data from a cubic function corrupted by Gaussian noise using linear (M1) and 5th degree polynomial (M5) models:
a) Bias(M1) ≤ Bias(M5), Variance(M1) ≤ Variance(M5)
b) Bias(M1) ≥ Bias(M5), Variance(M1) ≤ Variance(M5)
c) Bias(M1) ≤ Bias(M5), Variance(M1) ≥ Variance(M5)
d) Bias(M1) ≥ Bias(M5), Variance(M1) ≥ Variance(M5)
Show Answer
Answer: b) Bias(M1) ≥ Bias(M5), Variance(M1) ≤ Variance(M5)
Explanation: Linear model (M1) cannot capture the cubic relationship, so it has high bias but low variance (simple model). 5th degree polynomial (M5) can fit the cubic function well, so it has low bias but high variance (complex model). This is the classic bias-variance tradeoff: simpler models have higher bias and lower variance.
Question 24: Probability (Chessboard - Version 2)
Two squares are chosen at random on a chessboard. What is the probability that they have a side in common?
a) 1/36
b) 1/9
c) 2/9
d) 1/18
Show Answer
Answer: d) 1/18
Explanation: Same as Question 8:
- Total ways to choose 2 squares from 64: C(64,2) = 2016
- Adjacent pairs: 4 corner squares (2 neighbors each) + 24 edge squares (3 neighbors each) + 36 interior squares (4 neighbors each)
- Total adjacent pairs = (4×2 + 24×3 + 36×4)/2 = 112
- Probability = 112/2016 = 1/18
Question 25: System of Equations (Version 2)
The system 2x+y-z=1, x-2y+z=-2, -x+2y-z=-1 has how many solutions?
a) 0
b) 1
c) 2
d) Infinitely many
Show Answer
Answer: a) 0
Explanation: Looking at equations 2 and 3:
- x - 2y + z = -2
- -x + 2y - z = -1 Adding these equations: 0 = -3, which is a contradiction. Therefore, the system has no solutions.
Question 26: Softmax Output Properties
For a neural network with softmax output layer with 4 classes, which is always true about the outputs o1, o2, o3, o4?
a) Each oᵢ is between 0 and 1, and they sum to 1 b) Each oᵢ can be negative c) They can sum to more than 1 d) Softmax is only for binary classification
Show Answer
Answer: a) Each oᵢ is between 0 and 1, and they sum to 1
Explanation: Softmax formula: oᵢ = exp(zᵢ) / Σ exp(zⱼ). Since exp is always positive, each oᵢ ∈ (0,1) and Σoᵢ = 1 by construction — making it a proper probability distribution.
Question 27: L1 vs L2 Regularization
Which statement about L1 (Lasso) vs L2 (Ridge) regularization is correct?
a) L1 produces sparse solutions; L2 distributes weight across features b) L2 produces sparse solutions; L1 distributes weight across features c) Both produce sparse solutions d) Neither affects feature selection
Show Answer
Answer: a) L1 produces sparse solutions; L2 distributes weight across features
Explanation: L1 penalty (|w|) can drive weights exactly to zero, effectively selecting features — useful when many features are irrelevant. L2 penalty (w²) shrinks weights smoothly toward zero but rarely to exactly zero — it prefers many small weights rather than a few large ones.
Question 28: Naive Bayes Assumption
What is the key assumption made by the Naive Bayes classifier?
a) All features are correlated with each other b) Features are conditionally independent given the class label c) The data follows a uniform distribution d) The decision boundary must be linear
Show Answer
Answer: b) Features are conditionally independent given the class label
Explanation: Naive Bayes computes P(y|x₁,…,xₙ) ∝ P(y) × Π P(xᵢ|y). This product factorisation assumes P(x₁,…,xₙ|y) = Π P(xᵢ|y), i.e., each feature is independent of every other feature given the class. Despite this "naive" assumption often being violated in practice, the classifier works surprisingly well.
Question 29: ROC-AUC Interpretation
A model has AUC = 0.5. What does this mean?
a) The model is perfect b) The model performs no better than random chance c) The model always predicts the majority class d) The model has 50% accuracy
Show Answer
Answer: b) The model performs no better than random chance
Explanation: AUC (Area Under the ROC Curve) ranges from 0 to 1.
- AUC = 1.0: perfect classifier
- AUC = 0.5: random classifier (ROC curve is the diagonal line y=x)
- AUC < 0.5: worse than random (classifier is inverting predictions)
Note: AUC = 0.5 does NOT directly mean 50% accuracy; it measures the rank-ordering ability across thresholds.
Question 30: K-Fold Cross Validation
In 5-fold cross validation on a dataset of 1000 samples, how many samples are used for training in each fold?
a) 200 b) 500 c) 800 d) 1000
Show Answer
Answer: c) 800
Explanation: In k-fold CV the dataset is split into k equal parts. In each of the 5 iterations, 1 fold (200 samples) is used for validation and the remaining 4 folds (800 samples) are used for training. This gives 5 independent performance estimates that are then averaged.
Question 31: Determinant of a 3×3 Matrix
The determinant of matrix A = [[1,2,3],[0,1,4],[5,6,0]] is:
a) 1 b) -7 c) 7 d) -1
Show Answer
Answer: a) 1
Explanation: Expanding along the first row: det(A) = 1×(1×0 - 4×6) - 2×(0×0 - 4×5) + 3×(0×6 - 1×5) = 1×(0-24) - 2×(0-20) + 3×(0-5) = -24 + 40 - 15 = 1
Question 32: Conditional Probability
A bag contains 3 red and 2 blue balls. Two balls are drawn without replacement. Given the first ball is red, what is the probability the second ball is also red?
a) 3/5 b) 2/5 c) 1/2 d) 3/4
Show Answer
Answer: c) 1/2
Explanation: After drawing one red ball, the bag has 2 red and 2 blue balls (4 total). P(2nd red | 1st red) = 2/4 = 1/2.
Question 33: Information Gain / Entropy
A dataset of 8 samples has 4 positive and 4 negative labels. What is the entropy?
a) 0 b) 0.5 c) 1 d) 2
Show Answer
Answer: c) 1
Explanation: Entropy H = -Σ pᵢ log₂(pᵢ). With p(+) = 1/2 and p(-) = 1/2: H = -(1/2)log₂(1/2) - (1/2)log₂(1/2) = -(1/2)(-1) - (1/2)(-1) = 1.
Entropy is maximised at 1 (in bits) when classes are equally distributed — maximum uncertainty.
Question 34: SVM Margin
In Support Vector Machines, the optimal hyperplane is the one that:
a) Minimises the margin between classes b) Maximises the margin between the nearest points of different classes c) Passes through the centroid of each class d) Minimises training error regardless of margin
Show Answer
Answer: b) Maximises the margin between the nearest points of different classes
Explanation: The SVM objective is to find the hyperplane with the largest margin — the distance between the nearest data points (support vectors) from each class. A larger margin generally leads to better generalisation on unseen data. The margin width is 2/||w||, so maximising margin is equivalent to minimising ||w||.
Question 35: Backpropagation Chain Rule
In backpropagation, gradients are computed using:
a) Forward pass only b) The chain rule of calculus c) Finite differences only d) Newton's method
Show Answer
Answer: b) The chain rule of calculus
Explanation: Backpropagation efficiently computes gradients of the loss with respect to all parameters by applying the chain rule layer by layer from the output back to the input. ∂L/∂wᵢ = (∂L/∂aₙ) × (∂aₙ/∂aₙ₋₁) × … × (∂a₁/∂wᵢ) This avoids redundant computation through dynamic programming.
Question 36: Gradient of Sigmoid
The derivative of the sigmoid function σ(x) = 1/(1+e^(-x)) is:
a) σ(x)(1 - σ(x)) b) σ(x)² c) 1 - σ(x)² d) e^(-x)/(1+e^(-x))
Show Answer
Answer: a) σ(x)(1 - σ(x))
Explanation: Let σ = 1/(1+e^(-x)). dσ/dx = e^(-x)/(1+e^(-x))² = [1/(1+e^(-x))] × [e^(-x)/(1+e^(-x))] = σ × (1 - σ).
This elegant form means you can reuse the forward-pass value σ during backprop — no extra computation.
Question 37: Convolutional Layer Output Size
An input image of size 32×32×3 is passed through a Conv layer with 16 filters of size 5×5, stride 1, no padding. What is the output size?
a) 32×32×16 b) 28×28×16 c) 28×28×3 d) 16×16×16
Show Answer
Answer: b) 28×28×16
Explanation: Output spatial size = (W - F + 2P)/S + 1 = (32 - 5 + 0)/1 + 1 = 28. The number of output channels equals the number of filters = 16. Output: 28×28×16.
Question 38: Random Forest vs Decision Tree
Which statement best explains why Random Forests generally outperform a single Decision Tree?
a) Random Forests train faster than a single tree b) They reduce variance by averaging many uncorrelated trees c) They eliminate bias completely d) A single tree always overfits, regardless of depth
Show Answer
Answer: b) They reduce variance by averaging many uncorrelated trees
Explanation: A deep decision tree has low bias but high variance — it overfits training data. Random Forest builds many trees using bootstrap samples + random feature subsets (bagging + feature randomness), which decorrelates the trees. Averaging over many uncorrelated trees reduces variance while keeping bias low, improving generalisation.
Question 39: Handling Missing Data
Which method is most appropriate when a numerical feature has ~5% missing values and the data is Missing At Random (MAR)?
a) Delete all rows with missing values b) Replace with mean or median imputation c) Replace all missing values with 0 d) Ignore the feature entirely
Show Answer
Answer: b) Replace with mean or median imputation
Explanation: With only 5% missing values, deleting rows wastes data. Mean imputation works when data is normally distributed; median is more robust to outliers. Replacing with 0 introduces bias (assumes 0 is a meaningful value). Dropping the feature discards potentially predictive information. More advanced: model-based imputation (e.g., KNN, MICE) can further improve quality.
Question 40: Probability — Dice Problem
Two fair six-sided dice are rolled. What is the probability that the sum equals 8?
a) 5/36 b) 1/6 c) 7/36 d) 4/36
Show Answer
Answer: a) 5/36
Explanation: Favourable outcomes (sum = 8): (2,6),(3,5),(4,4),(5,3),(6,2) → 5 outcomes. Total outcomes: 6×6 = 36. P(sum=8) = 5/36.
💻 Part B – Amazon ML Summer SchoolCoding Questions
Problem 1: Statistical Calculations (Mean, Median, Mode)
Given 'n' integers, calculate their mean, median and mode with specific precision requirements.
Function Signature
function calculateStats(input1: number, input2: number[]): [number, number, number]
Requirements
- Mean and median: Must be correct to six decimal places
- Mode: Return as integer (smallest number in case of ties)
Definitions
Mean
Defined as the average of all numbers in the array:
Mean = (sum of all elements) / (number of elements)
Median
Defined as the middle element of the sorted array:
- If n is even: median = average of two middle elements
- If n is odd: median = middle element
Note: Array must be sorted in ascending order for median calculation.
Mode
Defined as the number with the highest frequency:
- If multiple numbers have same highest frequency, choose the smallest number
Input Specification
input1: Integer (1 ≤ input1 ≤ 1000) - length of arrayinput2: Integer array containing 'input1' integers
Output Specification
output1: Mean (double with 6 decimal places)output2: Median (double with 6 decimal places)output3: Mode (integer)
Test Cases
Example 1
Input1: 3
Input2: [1, 2, 3]
Output: 2.000000, 2.000000, 1
Example 2
Input1: 5
Input2: [41, 18467, 6334, 26500, 19169]
Output: 14102.200000, 18467.000000, 41
Calculation for Example 2:
- Mean: (41 + 18467 + 6334 + 26500 + 19169) / 5 = 14102.200000
- Median: Sorted array [41, 6334, 18467, 19169, 26500] → 18467.000000
- Mode: All elements appear once, smallest is 41
Problem 2: Robot String Manipulation
There are three robots named Ray, Ben and Kevin. Initially Ray has a string S of length N, while the other two robots have empty strings. We can make either of the following moves:
- Move 1: Remove the first character from Ray's string and append it to Ben's string
- Move 2: Remove the last character from Ben's string and append it to Kevin's string
You must perform either of the two moves mentioned above in such a way that the strings left with Ray and Ben are empty and the string left with Kevin is lexicographically the smallest.
Task
Return the lexicographically smallest string that Kevin has after completing this activity.
Important Note
For any two given strings, a string is said to be lexicographically smaller than the other if it comes before the other string in the dictionary.
Constraints
- Input: String S of length N
- Output: Lexicographically smallest string that Kevin will have
Approach Hints
- This is essentially a stack-based problem
- Ben's string acts like a stack (LIFO - Last In, First Out)
- Need to find optimal sequence of moves to minimize lexicographic order
Problem 3: Minimum Cost Flight Path
There are N cities in a country. George starts at city 1 (airport) and wants to reach city N. From any city i, he can travel to:
- City (i+1) if it exists, OR
- City (i+3) if it exists
Cost Calculation
Flight cost between cities i and j is calculated as:
Cost = |Cost[i] - Cost[j]|
where Cost[i] represents the cost value for city i in the given array.
Task
Find and return the minimum possible cost to reach city N from city 1.
Constraints
- Number of cities N > 3
- Use 1-based indexing
- Can only move to (i+1) or (i+3) from city i
Input Specification
input1: Integer N (number of cities)input2: Integer array A (cost values for each city)
Output Specification
- Return minimum total cost to reach city N
Test Cases
Example 1
Input1: 4
Input2: [1, 4, 5, 2]
Output: 1
Explanation:
- Direct path: City 1 → City 4 (using i+3 rule)
- Cost: |Cost[1] - Cost[4]| = |1 - 2| = 1
Example 2
Input1: 6
Input2: [4, 12, 13, 18, 10, 12]
Output: 10
Explanation: Optimal path: City 1 → City 2 → City 3 → City 6
- City 1 → City 2: |4 - 12| = 8
- City 2 → City 3: |12 - 13| = 1
- City 3 → City 6: |13 - 12| = 1
- Total cost: 8 + 1 + 1 = 10
Algorithm Approach
- This is a Dynamic Programming problem
- Can also be solved using BFS/Dijkstra's algorithm
- State:
dp[i] = minimum cost to reach city i - Transition:
dp[i] = min(dp[i-1] + cost(i-1,i), dp[i-3] + cost(i-3,i))
✅ Complete Python Solutions
Solution 1: Statistical Calculations
from collections import Counter
def calculateStats(n, arr):
# Mean
mean = sum(arr) / n
# Median
arr.sort()
if n % 2 == 0:
median = (arr[n // 2 - 1] + arr[n // 2]) / 2.0
else:
median = float(arr[n // 2])
# Mode (smallest number in case of ties)
freq = Counter(arr)
max_freq = max(freq.values())
mode = min(k for k, v in freq.items() if v == max_freq)
return round(mean, 6), round(median, 6), mode
# Test
print(calculateStats(3, [1, 2, 3])) # 2.0, 2.0, 1
print(calculateStats(5, [41, 18467, 6334, 26500, 19169])) # 14102.2, 18467.0, 41
Time Complexity: O(n log n) — dominated by sorting for median. Space Complexity: O(n) — for the Counter.
Solution 2: Robot String Manipulation (Stack-Based)
Key Insight: Ben's string behaves like a stack — you push characters onto it (Move 1) and pop from the top to Kevin (Move 2). The optimal strategy: before pushing the next character from Ray onto Ben, greedily pop everything from Ben that is ≤ the current character.
def lexicographicallySmallest(s):
n = len(s)
# Precompute suffix minimum: min_suffix[i] = min(s[i:])
min_suffix = [''] * (n + 1)
min_suffix[n] = chr(ord('z') + 1) # sentinel
for i in range(n - 1, -1, -1):
min_suffix[i] = min(s[i], min_suffix[i + 1])
ben = [] # stack
kevin = []
for i, ch in enumerate(s):
ben.append(ch)
# Pop from Ben to Kevin while top of Ben <= min of remaining Ray characters
while ben and ben[-1] <= min_suffix[i + 1]:
kevin.append(ben.pop())
# Drain remaining characters from Ben to Kevin
while ben:
kevin.append(ben.pop())
return ''.join(kevin)
# Test
print(lexicographicallySmallest("dcba")) # abcd
print(lexicographicallySmallest("cbad")) # abcd
Time Complexity: O(n) — each character is pushed/popped at most once. Space Complexity: O(n) — for the Ben stack and Kevin output.
Solution 3: Minimum Cost Flight Path (DP)
import math
def minCostFlight(n, cost):
# 1-indexed: cost[0] is city 1, cost[n-1] is city n
dp = [math.inf] * n
dp[0] = 0
for i in range(1, n):
# Come from city i-1 (i+1 rule, 0-indexed: from i-1)
if i >= 1:
dp[i] = min(dp[i], dp[i - 1] + abs(cost[i] - cost[i - 1]))
# Come from city i-3 (i+3 rule, 0-indexed: from i-3)
if i >= 3:
dp[i] = min(dp[i], dp[i - 3] + abs(cost[i] - cost[i - 3]))
return dp[n - 1]
# Test
print(minCostFlight(4, [1, 4, 5, 2])) # 1
print(minCostFlight(6, [4, 12, 13, 18, 10, 12])) # 10
Time Complexity: O(n) — single pass. Space Complexity: O(n) — dp array (optimisable to O(1) with three variables).
💻 Additional Coding Problems (with Solutions)
Problem 4: Longest Common Subsequence Length
Given two strings, find the length of their Longest Common Subsequence (LCS).
Input: s1 = "ABCBDAB", s2 = "BDCABA"
Output: 4 (LCS = "BCBA" or "BDAB")
def lcs(s1, s2):
m, n = len(s1), len(s2)
dp = [[0] * (n + 1) for _ in range(m + 1)]
for i in range(1, m + 1):
for j in range(1, n + 1):
if s1[i - 1] == s2[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
return dp[m][n]
print(lcs("ABCBDAB", "BDCABA")) # 4
Time: O(m×n) | Space: O(m×n) — reducible to O(n) with rolling array.
Problem 5: K Most Frequent Elements
Given an integer array and an integer k, return the k most frequent elements.
Input: nums = [1,1,1,2,2,3], k = 2
Output: [1, 2]
import heapq
from collections import Counter
def topKFrequent(nums, k):
freq = Counter(nums)
# Use a min-heap of size k for O(n log k)
return heapq.nlargest(k, freq.keys(), key=lambda x: freq[x])
print(topKFrequent([1, 1, 1, 2, 2, 3], 2)) # [1, 2]
Bucket Sort variant — O(n):
def topKFrequent_linear(nums, k):
freq = Counter(nums)
buckets = [[] for _ in range(len(nums) + 1)]
for num, count in freq.items():
buckets[count].append(num)
result = []
for i in range(len(buckets) - 1, -1, -1):
result.extend(buckets[i])
if len(result) >= k:
return result[:k]
return result
Problem 6: Median in a Data Stream
Design a data structure that supports adding integers and querying the median efficiently.
import heapq
class MedianFinder:
def __init__(self):
self.low = [] # max-heap (negate values)
self.high = [] # min-heap
def addNum(self, num):
heapq.heappush(self.low, -num)
# Balance: largest of low must be <= smallest of high
if self.high and (-self.low[0]) > self.high[0]:
heapq.heappush(self.high, -heapq.heappop(self.low))
# Keep sizes balanced (low can be at most 1 larger)
if len(self.low) > len(self.high) + 1:
heapq.heappush(self.high, -heapq.heappop(self.low))
elif len(self.high) > len(self.low):
heapq.heappush(self.low, -heapq.heappop(self.high))
def findMedian(self):
if len(self.low) > len(self.high):
return float(-self.low[0])
return (-self.low[0] + self.high[0]) / 2.0
# Test
mf = MedianFinder()
for x in [5, 15, 1, 3]:
mf.addNum(x)
print(mf.findMedian()) # 5.0, 10.0, 5.0, 4.0
Time: O(log n) per insertion, O(1) per query | Space: O(n)
Problem 7: Maximum Subarray Sum (Kadane's Algorithm)
Find the maximum sum of any contiguous subarray.
Input: [-2,1,-3,4,-1,2,1,-5,4]
Output: 6 (subarray [4,-1,2,1])
def maxSubarraySum(nums):
max_sum = current = nums[0]
for num in nums[1:]:
current = max(num, current + num)
max_sum = max(max_sum, current)
return max_sum
print(maxSubarraySum([-2,1,-3,4,-1,2,1,-5,4])) # 6
Time: O(n) | Space: O(1)
Problem 8: Valid Parentheses
Given a string of brackets, determine if it is valid.
Input: "{[()]}" → True
Input: "{[(])}" → False
def isValid(s):
stack = []
mapping = {')': '(', '}': '{', ']': '['}
for ch in s:
if ch in mapping:
top = stack.pop() if stack else '#'
if mapping[ch] != top:
return False
else:
stack.append(ch)
return not stack
print(isValid("{[()]}")) # True
print(isValid("{[(])}")) # False
Time: O(n) | Space: O(n)
📚 Key Topics to Study for Amazon ML Summer School
Mathematics (Part A — 20 MCQs)
| Topic | Key Concepts |
|---|---|
| Linear Algebra | Matrix rank, eigenvalues/eigenvectors, determinants, matrix inverse, systems of equations |
| Probability | Bayes' theorem, conditional probability, expectation, variance, covariance, correlation |
| Statistics | Mean/median/mode, unbiased estimators, p-value, Type I/II errors, distributions |
| Calculus | Derivatives, chain rule, logarithmic differentiation, gradient, partial derivatives |
Machine Learning Concepts (Part A — ML questions)
| Topic | Key Concepts |
|---|---|
| Supervised Learning | Linear/logistic regression, decision trees, SVM, bias-variance tradeoff |
| Unsupervised Learning | K-means, PCA, dimensionality reduction |
| Neural Networks | Feedforward NNs, backpropagation, activation functions (sigmoid, ReLU, softmax) |
| Model Evaluation | Cross-validation, AUC-ROC, precision-recall, overfitting/underfitting |
| Regularisation | L1 (Lasso), L2 (Ridge), dropout |
Data Structures & Algorithms (Part B — 2 problems)
| Pattern | Examples |
|---|---|
| Dynamic Programming | Minimum cost paths, LCS, climbing stairs, Kadane's |
| Stacks / Queues | String manipulation (robot problem), valid parentheses |
| Heaps | Top-K elements, median in stream |
| Sorting + Statistics | Mean/median/mode computation |
| Graph / BFS | Shortest path variants |
30-Day Study Plan
| Week | Focus |
|---|---|
| Week 1 | Probability & Statistics — Bayes, distributions, hypothesis testing |
| Week 2 | Linear Algebra — eigenvalues, rank, systems of equations, matrix operations |
| Week 3 | ML Algorithms — regression, classification, clustering, evaluation metrics |
| Week 4 | DSA Practice — DP, stacks, heaps, sorting; solve 2 problems per day on LeetCode |
Below are problem statements similar to those reportedly asked in previous Amazon ML Summer School coding tests, based on participant experiences:
1. Mean, Median, Mode Calculation
Given an array of integers, write a function to compute the mean, median, and mode.
2. Climbing Stairs Variant
Given a staircase with n steps, you can climb 1 or 2 steps at a time. Find the number of distinct ways to reach the top.
3. Array Manipulation with Constraints
Given an array of package weights and a maximum weight limit, compute the minimum cost to deliver all packages by choosing consecutive packages in a single trip, where the cost is based on the sum of weights in each trip.
4. Run Length Encoding
Given a string, return its run-length encoding (e.g., "aaaaabb" → "a5b2").
5. Median in a Stream
Given a stream of integers, write a function to add numbers to the stream and return the median after each addition.
6. Maximum Subarray Sum
Given an array of integers (positive and negative), find the maximum sum of any contiguous subarray.
7. Valid Parentheses
Given a string containing only parentheses characters ('(', ')', '{', '}', '[', ']'), determine if the input string is valid. A string is valid if all open brackets are closed in the correct order.
8. Top K Frequent Elements
Given an array of integers and an integer k, return the k most frequent elements in the array. You can return the answer in any order.
9. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.
10. Minimum Cost to Merge Stones
Given an array of integers representing stone weights and an integer k, you can merge exactly k consecutive stones into one stone with weight equal to their sum. Find the minimum cost (sum of merged weights) to merge all stones into one.
Apply now if you haven't applied it yet- Check now
Join Telegram group for any doubts & discussions!