Day206 - Leetcode: Python 217 & SQL 175,176 & DL Review
Python 217: Contains Duplicate / SQL 175,176: Second-highest Salary / DL Review: Transfer Learning & Fine-Tuning & CNNs

π© Python Review
217. Contains Duplicate
- Given an integer array
nums, returntrueif any value appears at least twice in the array, and returnfalseif every element is distinct.
### My answer
class Solution(object):
def containsDuplicate(self, nums: List[int] -> Bool):
if len(nums) != sort(len(nums)) # A bit confused
else true
return false
"""
:type nums: List[int]
:rtype: bool
---> Check numbers of list and compare
"""
### Solution
class Solution(object):
def containsDuplicate(self, nums: List[int]) -> bool:
if len(nums) == len(set(nums)): # Use SET
return False
return True
From my attempt,
- Many syntax errors. I was confused about how to compare the number of list indexes.
- Should be
-> bool(lowercase), not-> Bool. - I missed a colon (
:) after theifstatement.
From the corrected solution,
set(nums)removes duplicates because a set cannot contain repeated values.- The logic:
- If the lengths are equal -> no duplicates; return
true. - If the lengths are unequal -> duplicates exist; return
false,
- If the lengths are equal -> no duplicates; return
π¨ SQL Review
175. Combine Two Tables
-- My Answer
select a.firstName, a.lastName, b.city, b.state
from Person a
outer join Address b on a.personId = b.personId;
-- Solution
SELECT a.firstName, a.lastName, b.city, b.state
FROM Person a
LEFT JOIN Address b
ON a.personId = b.personId;
In PostgreSQL, the OUTER JOIN must be specified more explicitly β we can use LEFT JOIN, RIGHT JOIN, or FULL OUTER JOIN depending on the requirement.
176. Second-Highest Salary
-- My Answer
select dist(salary) from Employee
Limit 1;
-- Do I have to use group by? ==> NO, You do not need to.
-- Do I have to put any constraints for null value? ==> No, Postgre automatically ignores Nulls.
-- Solution
select distinct salary from Employee
order by salary desc
offset 1 limit 1;
From my attempt.
DIST ()is not a valid function in PostgreSQL.- I must write up
SELECT DISTINCT.
- I must write up
- I forgot to use
offsetto calculate the second-highest one.
From the solution,
offsetskips a certain number of rows. From here, we skip the first highest salary, and then provide the second highest one as requested.
π¦ DL Review
1. Transfer Learning & Fine-Tuning
Transfer learning leverages a model pretrained on a large dataset (e.g., ImageNet, BERT), and adapts it to a new task with limited data.
- Feature extraction: Freeze pre-trained layers and use them as feature generators.
- Fine-tuning: Unfreeze some layers and retrain with task-specific data.
Why It Matters
- Reduces training time and data requirements.
- Often achieves **state-of-the-art results **on small datasets.
- Common in NLP, CV, and speech applications.
βTransfer learning uses pre-trained models as a starting point and adapts them to new tasks through fine-tuning. This approach saves computation, requires less labeled data, and usually improves generalization.β
MLOps Angle
- When deploying, choosing how much to fine-tune matters for latency and inference costs. Pretrained embeddings/models also introduce external dependencies, so versioning and monitoring are key.
2. Convolutional Neural Networks (CNNs)
CNNs are specialized neural networks designed for grid-like data (e.g., images).
- Convolutions: Learn spatial filters that detect local features.
- Pooling: Reduces dimensionality, adds translation invariance.
- Stacking layers: Builds hierarchical representations (edges β shapes β objects).
Why It Matters
- Standard for image classification, object detection, and segmentation.
- Efficient due to parameter sharing and local connectivity.
- Inspiration behind modern architecture (e.g., ResNets, EfficientNet, ConvNeXt),
βConvolutional Neural Networks use parameter-sharing filters to detect local patterns, making them efficient and powerful for image tasks. By stacking layers, CNNs learn hierarchical representations, from edges to complex objects.β
MLOps Angle
- CNNs dominate computer vision pipelines. In deployment, they must be optimized for inference (via quantization, pruning, and ONNX export) to meet latency constraints on edge devices.
Leave a comment