0% found this document useful (0 votes)
12 views9 pages

Interview Prep1

The document contains a comprehensive set of interview questions and answers related to Python programming, covering topics such as data types, memory management, concurrency, and SQL. It also includes practice questions for a candidate named Mehul, along with answers that demonstrate knowledge of object-oriented programming, performance optimization, and automated testing. Additionally, there are questions based on a job description that highlight the candidate's experience with backend development, system design, and database management.

Uploaded by

2019ugec100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

Interview Prep1

The document contains a comprehensive set of interview questions and answers related to Python programming, covering topics such as data types, memory management, concurrency, and SQL. It also includes practice questions for a candidate named Mehul, along with answers that demonstrate knowledge of object-oriented programming, performance optimization, and automated testing. Additionally, there are questions based on a job description that highlight the candidate's experience with backend development, system design, and database management.

Uploaded by

2019ugec100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Section 1: Interview Questions with Answers

1. What are Python’s key data types and their use cases?

Answer: int, float, str, bool, list, tuple, set, dict. Each serves specific needs—e.g., dict for

key-value mapping, set for uniqueness, tuple for immutability.

2. Explain the difference between @staticmethod and @classmethod.

Answer: @staticmethod doesn’t take self or cls. @classmethod takes cls and can modify

class-level attributes.

3. What is a Python generator and where have you used it?

Answer: Generators are iterators created using yield. Used in file processing for

memory efficiency.

4. How does Python handle memory management?

Answer: Through reference counting and garbage collection.

5. Explain multiple inheritance and MRO in Python.

Answer: Python supports multiple inheritance. MRO uses C3 linearization to determine

method resolution.

6. What are dunder (magic) methods? Give examples.

Answer: Special methods like __init__, __str__, __eq__. Used for customization and

operator overloading.

7. What is the difference between deepcopy and copy in Python?

Answer: copy() creates a shallow copy; deepcopy() copies all objects recursively.

8. Explain the concept of duck typing in Python.

Answer: Python focuses on behavior, not type. If an object has the necessary methods,

it's acceptable.

9. How do you manage dependency injection in Python?

Answer: Using constructor injection, function arguments, or libraries like

dependency-injector.

10. What are Python descriptors and how are they used?
Answer: Descriptors define __get__, __set__, __delete__. Used in properties and ORMs.

11. How is a set implemented in Python internally?

Answer: As a hash table, offering O(1) average time for insert/delete/lookup.

12. When would you prefer a deque over a list?

Answer: When frequent appends/pops from both ends are required.

13. Time complexity of dict.get() and list.index()?

Answer: dict.get() is O(1) average, list.index() is O(n).

14. How does a heap differ from a balanced BST?

Answer: Heap maintains partial order; BST maintains total order.

15. Which algorithm would you use for cycle detection in a directed graph?

Answer: DFS with recursion stack or Kahn’s algorithm.

16. What are indexes in SQL and when should you not use them?

Answer: Indexes speed up queries but slow writes. Avoid on frequently updated

columns.

17. Difference between WHERE and HAVING?

Answer: WHERE filters before aggregation, HAVING after.

18. What is normalization? Explain 1NF, 2NF, and 3NF.

Answer: 1NF: atomic values, 2NF: no partial dependencies, 3NF: no transitive

dependencies.

19. How would you design a schema to store file upload metadata efficiently?

Answer: Use file_id, filename, upload_date, user_id, status. Index upload_date.

20. What is the difference between LEFT JOIN and INNER JOIN?

Answer: INNER JOIN returns only matches. LEFT JOIN includes all from left table.
Section 2: Practice Questions for Mehul to Answer

1. Explain how Python handles concurrency. Where have you used it?

2. Describe a class you wrote recently using inheritance and polymorphism.

3. How does exception handling work in Python? What are custom exceptions?

4. Describe __slots__ and its benefits.

5. What are metaclasses? Have you ever used them?

6. How is encapsulation achieved in Python?

7. Compare composition vs inheritance with real code example.

8. What are type hints? How do you enforce them?

9. What are design patterns you've used in Python?

10. What’s the difference between shallow and deep copying objects in practice?

11. What’s the difference between clustered and non-clustered indexes?

12. Write a query to find the second highest salary from an employee table.

13. How would you handle transactions in Python (e.g., using psycopg2 or

SQLAlchemy)?

14. What is ACID? Explain each with a real example from your work.

15. How do you monitor and debug slow SQL queries?

16. What will list(flatten([1, [2, [3, 4]], 5])) return? Explain the recursion flow.

17. What pattern is used in the Singleton class and why is __new__ overridden?

18. What are dataclasses useful for? Compare with NamedTuple.

19. What’s the time complexity of the memoized fibonacci function? Any risks?

20. What will Counter('hello world') return? How is it different from a dict?
Section 2: Practice Questions for Mehul to Answer (with Answers)

1. Explain how Python handles concurrency. Where have you used it?

Answer: Python handles concurrency using threads (via `threading`), multiprocessing,

and async IO (via `asyncio`). Due to the GIL, CPU-bound tasks benefit more from

multiprocessing, while IO-bound tasks can use threading or async. I’ve used async

libraries for file ingestion and batch processing to handle large volumes of MIS data

efficiently.

2. Describe a class you wrote recently using inheritance and polymorphism.

Answer: At Cashfree, I created a base `FileParser` class with methods like `parse()` and

`validate()`, and derived classes like `CSVParser`, `ExcelParser` that overrode these

methods, enabling polymorphic file processing.

3. How does exception handling work in Python? What are custom exceptions?

Answer: Python uses try-except blocks for exception handling. You can define custom

exceptions by inheriting from `Exception`. This makes error reporting more descriptive

and manageable.

4. Describe __slots__ and its benefits.

Answer: `__slots__` is used to restrict the dynamic creation of attributes and save

memory by avoiding the default `__dict__`. It's beneficial when many instances of a

class are created.

5. What are metaclasses? Have you ever used them?

Answer: Metaclasses define class behavior. They’re classes of classes. I’ve explored

them to modify class creation logic, like auto-registering classes in a registry.

6. How is encapsulation achieved in Python?

Answer: By using private variables (e.g., `_var`, `__var`) and providing controlled

access through getter/setter methods or `@property` decorators.

7. Compare composition vs inheritance with real code example.

Answer: Inheritance uses ‘is-a’ while composition uses ‘has-a’. At Sugar Crystal, instead
of inheriting `Logger`, I passed it to services as a dependency, promoting modular

design.

8. What are type hints? How do you enforce them?

Answer: Type hints specify expected variable types. Enforced using tools like `mypy`.

Example: `def greet(name: str) -> str:`.

9. What are design patterns you've used in Python?

Answer: Singleton for shared services, Factory for parser instantiation, and Decorator

for logging and timing utilities.

10. What’s the difference between shallow and deep copying objects in practice?

Answer: Shallow copy references nested objects. Deep copy clones them. Use

`copy.deepcopy()` to avoid side effects in nested structures.

11. What’s the difference between clustered and non-clustered indexes?

Answer: Clustered index reorders the table rows to match the index, only one allowed

per table. Non-clustered index creates a separate structure.

12. Write a query to find the second highest salary from an employee table.

Answer: SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary)

FROM employees);

13. How would you handle transactions in Python (e.g., using psycopg2 or

SQLAlchemy)?

Answer: Using `with` blocks or `.begin()` for SQLAlchemy, and

`conn.commit()`/`conn.rollback()` for psycopg2 to ensure atomicity.

14. What is ACID? Explain each with a real example from your work.

Answer: Atomicity, Consistency, Isolation, Durability. For example, during file recon,

transactions ensured atomic inserts and rollbacks on failure, preserving consistency.

15. How do you monitor and debug slow SQL queries?

Answer: Using EXPLAIN plans, indexing analysis, and tools like pg_stat_statements or

slow query logs. Also used Grafana + Prometheus for DB metrics.


16. What will list(flatten([1, [2, [3, 4]], 5])) return? Explain the recursion flow.

Answer: Returns [1, 2, 3, 4, 5]. Each list is recursively unpacked using `yield from` until

atomic elements are reached.

17. What pattern is used in the Singleton class and why is __new__ overridden?

Answer: Singleton. `__new__` ensures only one instance is created and reused.

18. What are dataclasses useful for? Compare with NamedTuple.

Answer: Dataclasses auto-generate boilerplate code like `__init__`, support mutability.

NamedTuple is immutable and lightweight.

19. What’s the time complexity of the memoized fibonacci function? Any risks?

Answer: Time complexity is O(n). Risk: mutable default argument (memo={}) may

retain state across calls.

20. What will Counter('hello world') return? How is it different from a dict?

Answer: Returns frequency count: Counter({'l':3, 'o':2, 'h':1, 'e':1, ' ':1, 'w':1, 'r':1,

'd':1}). It's a subclass of dict with counting utilities.


Section 3: Questions Based on Job Description (with Answers)

1. What is the significance of object-oriented programming in backend development?

Answer: It promotes code modularity, reusability, and scalability, which are essential for

building maintainable backend systems.

2. How do you ensure the performance of backend services handling large datasets like

MIS files?

Answer: By optimizing queries, using batch processing, parallelism, and profiling

bottlenecks in processing pipelines.

3. What tools or methods do you use to identify and resolve performance bottlenecks in

APIs?

Answer: Profilers like cProfile, logging time stamps, and metrics in Grafana. Also

inspecting DB query plans and latency traces.

4. How would you design an authentication system using FastAPI?

Answer: Using OAuth2 or JWT tokens, secured endpoints, password hashing (bcrypt),

and token expiry for security.

5. What is your approach to automated testing in Python projects?

Answer: Use `unittest` or `pytest`, aim for high test coverage, mock external

dependencies, and automate testing in CI pipelines.

6. How do you implement input validation in FastAPI or Flask?

Answer: Using Pydantic models to define schemas and automatic validation via

decorators or route definitions.

7. Explain a scenario where Pydantic helped you catch runtime errors early.

Answer: In file ingestion, it ensured schema validation before DB writes, preventing

crashes and bad data ingestion.

8. How would you structure a Python project that involves multiple services and

modules?

Answer: Follow modular architecture—group by feature/domain, use services,


repositories, configs, and utils folders.

9. How does your experience with cron jobs help in system optimization?

Answer: Used cron for periodic tasks like detecting inactive users, offloading real-time

processing and reducing system load.

10. What challenges did you face while integrating third-party bank PGs in the recon

engine?

Answer: Variability in file formats, latency, authentication methods. Handled with

adapters, retries, and uniform schema mapping.

11. How do you ensure database queries remain performant at scale?

Answer: By using indexes, avoiding N+1 queries, batching writes, and monitoring with

query plans or pg_stat_statements.

12. What role does Docker play in backend development?

Answer: It ensures consistent environments across dev/stage/prod, simplifies

deployment, and is crucial for containerized microservices.

13. What is your experience with Git and GitHub workflows in a team setting?

Answer: Feature branches, PRs, code reviews, squash/rebase merges, GitHub Actions

for CI/CD workflows.

14. How do you monitor and maintain system uptime in production environments?

Answer: Through alerts, Grafana dashboards, error tracking, on-call rotations, and

structured logging.

15. Describe your approach to writing scalable APIs.

Answer: Design RESTful endpoints, paginate responses, use efficient serialization,

cache repeated calls, and async when needed.

16. What are some common design patterns you've used in backend development?

Answer: Singleton, Factory, Adapter, Repository—used to decouple components and

promote extensibility.

17. How does understanding throughput and latency help in designing better systems?
Answer: It helps in capacity planning, load testing, and optimizing response times for

high-load APIs.

18. How do you ensure that code follows OOPs guidelines and remains testable?

Answer: Use SOLID principles, dependency injection, composition over inheritance, and

separation of concerns.

19. How does your understanding of DBMS fundamentals reflect in real project

scenarios?

Answer: By designing normalized schemas, using transactions, foreign keys, and

enforcing data integrity across systems.

20. What excites you about Primenumbers Technologies' mission and how do you see

yourself contributing?

Answer: The focus on simplifying critical business intelligence aligns with my passion

for scalable backend systems. I bring strong experience in data-heavy backend

processing, which fits well with PN’s vision.

You might also like