Cognizant Questions

Athuluri AkhilAthuluri Akhil
13 min read

๐Ÿ Python Programming (15 Questions)

  1. What are Pythonโ€™s key features?
    Interpreted, high-level, dynamically typed, garbage-collected, supports OOP and functional programming.

  2. What are lists and tuples?

    • List: Mutable, uses []

    • Tuple: Immutable, uses ()

  3. What is a dictionary in Python?
    A key-value pair data structure defined using {}.

  4. What is list comprehension?
    A concise way to create lists: [x for x in range(5)]

  5. **What are *args and kwargs?

    • *args: Variable positional arguments

    • **kwargs: Variable keyword arguments

  6. What is a lambda function?
    An anonymous function: lambda x: x*2

  7. What is the difference between is and ==?

    • is: compares object identity

    • ==: compares values

  8. How is memory managed in Python?
    Through reference counting and garbage collection.

  9. What are Python generators?
    Functions using yield to return an iterator.

  10. What is the purpose of self in class methods?
    Refers to the instance of the class.

  11. Explain Python decorators.
    Functions that modify other functions using @decorator_name.

  12. What is the difference between deepcopy() and copy()?
    copy() is shallow; deepcopy() copies nested objects too.

  13. What are Python modules and packages?

  • Module: A single Python file

  • Package: A directory with __init__.py containing modules

  1. What is a virtual environment in Python?
    Isolated environment for project dependencies using venv.

  2. Explain exception handling in Python.
    Use try, except, else, and finally blocks.


๐Ÿ“Š Data Structures & Algorithms (10 Questions)

  1. What is the difference between a list and a set?
  • List: Ordered, allows duplicates

  • Set: Unordered, no duplicates

  1. How to implement a stack in Python?
    Using list: append() to push, pop() to remove.

  2. What is a queue and how to implement it?
    FIFO: Use collections.deque().

  3. What is the time complexity of dictionary operations?
    Average-case: O(1) for insert, delete, and lookup.

  4. What is a binary search?
    Efficient O(log n) search in sorted arrays.

  5. What is recursion? Provide an example.
    A function calling itself.

def factorial(n):
    return 1 if n == 0 else n * factorial(n-1)
  1. What is the difference between BFS and DFS?
  • BFS: Queue-based, level-order

  • DFS: Stack-based, depth-first

  1. What is the purpose of hashing?
    To allow fast access using keys, O(1) in average.

  2. What is the difference between mutable and immutable types?
    Mutable: Can be changed (list, dict),
    Immutable: Canโ€™t be changed (str, int, tuple)

  3. Sort a list of numbers in ascending order.
    sorted([3, 1, 2]) or list.sort()


๐Ÿงฑ Object-Oriented Programming (5 Questions)

  1. What are the four pillars of OOP?
    Encapsulation, Abstraction, Inheritance, Polymorphism.

  2. How is inheritance implemented in Python?

class A: pass  
class B(A): pass
  1. What is polymorphism in Python?
    Same interface, different behavior: method overriding/overloading.

  2. What is encapsulation?
    Restricting access using private/protected variables.

  3. Difference between class and object?
    Class is a blueprint; object is an instance of the class.


๐Ÿ—„๏ธ SQL & Database Basics (5 Questions)

  1. What is a primary key?
    Uniquely identifies rows in a table.

  2. What is the difference between WHERE and HAVING?

  • WHERE: Filters rows before grouping

  • HAVING: Filters after grouping

  1. Write a query to fetch the second highest salary.
SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
  1. What is normalization?
    Organizing data to reduce redundancy.

  2. Difference between INNER JOIN and LEFT JOIN?

  • INNER JOIN: Only matching rows

  • LEFT JOIN: All rows from left + matched from right


๐Ÿ’ก Aptitude & Logical Reasoning (5 Questions)

  1. If A = 5, B = 10, then A + B * 2 = ?
    5 + 10 * 2 = 25 (BODMAS)

  2. What is the next number in the sequence: 2, 4, 8, 16, ?
    32 (multiply by 2)

  3. A train 100m long crosses a pole in 5 seconds. Find speed.
    Speed = 100 / 5 = 20 m/s

  4. Solve: If x + y = 10 and x - y = 4, find x and y.
    x = 7, y = 3

  5. Which number doesn't belong: 3, 5, 7, 9, 11?
    9 (not prime)


๐Ÿ–ฅ๏ธ CS Fundamentals (OS, Networking) (5 Questions)

  1. What is an operating system?
    Software that manages hardware and software resources.

  2. What is a process and a thread?

  • Process: Independent program instance

  • Thread: Lightweight sub-process

  1. What is deadlock?
    A state where two or more processes wait indefinitely for each otherโ€™s resources.

  2. What is TCP/IP?
    Protocol suite for reliable network communication.

  3. Difference between HTTP and HTTPS?
    HTTPS is secure using SSL/TLS encryption.


๐Ÿง  HR + General (5 Questions)

  1. Tell me about yourself.
    Structure: Background โ†’ Skills โ†’ Projects โ†’ Why Cognizant.

  2. Why do you want to join Cognizant?
    Talk about innovation, learning culture, growth, global exposure.

  3. What are your strengths and weaknesses?
    Strength: Problem solving. Weakness: Overcommitting (add how you're improving it).

  4. Describe a challenging project you worked on.
    Share a STAR-format story (Situation, Task, Action, Result).

  5. Are you willing to relocate and work in shifts?
    โ€œYes, I am open to relocation and flexible with timings.โ€



๐Ÿ Python & Programming (15 Questions)

  1. What is the difference between range() and xrange()?
    In Python 3, only range() exists and returns an iterable. xrange() was in Python 2.

  2. What are Python's data types?
    int, float, bool, str, list, tuple, set, dict, NoneType, etc.

  3. What are iterators and iterables?

    • Iterable: Object over which we can iterate (like list)

    • Iterator: Object with __next__() method

  4. Explain Python slicing.
    Access sub-parts of sequences using list[start:stop:step].

  5. How do you handle file operations in Python?

     with open("file.txt", "r") as f:
         data = f.read()
    
  6. What is the purpose of pass, continue, and break?

    • pass: Placeholder

    • continue: Skips current iteration

    • break: Exits the loop

  7. What is the use of enumerate()?
    Returns both index and value:

     for i, v in enumerate(["a", "b"]): print(i, v)
    
  8. How to reverse a string in Python?
    s[::-1]

  9. How do you handle exceptions for multiple errors?

     try:
         ...
     except (ValueError, TypeError):
         ...
    
  10. What is duck typing in Python?
    โ€œIf it walks like a duck and quacks like a duck, itโ€™s a duckโ€ โ€“ focuses on behavior not type.

  11. How is Python dynamically typed?
    Variables do not require declaration of type.

  12. How to sort a dictionary by value?

sorted(d.items(), key=lambda x: x[1])
  1. What is a context manager in Python?
    Object with __enter__() and __exit__() used with with.

  2. What are Pythonโ€™s built-in data structures?
    List, Tuple, Set, Dictionary.

  3. What are nonlocal and global keywords?

  • global: Refers to global scope

  • nonlocal: Refers to enclosing functionโ€™s scope


๐Ÿ“Š DSA & Algorithms (10 Questions)

  1. What is the time complexity of linear search?
    O(n)

  2. How to detect a loop in a linked list?
    Floydโ€™s Cycle Detection (Tortoise & Hare)

  3. Explain binary search with code.

def binary_search(arr, x):
    low, high = 0, len(arr) - 1
    while low <= high:
        mid = (low + high) // 2
        if arr[mid] == x:
            return mid
        elif arr[mid] < x:
            low = mid + 1
        else:
            high = mid - 1
    return -1
  1. What is a heap?
    A complete binary tree used for priority queues.

  2. Difference between linear and binary search?

  • Linear: O(n), works on unsorted

  • Binary: O(log n), needs sorted array

  1. What is Big O notation?
    Describes upper bound of algorithm time/space complexity.

  2. What is a hash table?
    A structure that maps keys to values for fast lookup (Python dict uses it).

  3. Whatโ€™s the difference between recursion and iteration?

  • Recursion: Function calls itself

  • Iteration: Loop-based solution

  1. What is tail recursion?
    Recursion where the recursive call is the last statement.

  2. Implement Fibonacci using memoization.

from functools import lru_cache

@lru_cache
def fib(n):
    return n if n < 2 else fib(n-1) + fib(n-2)

๐Ÿงฑ OOP & Concepts (5 Questions)

  1. What is method overloading?
    Same method name, different parameters (not directly supported in Python).

  2. What is method overriding?
    Subclass provides specific implementation of a method already defined in parent.

  3. What is multiple inheritance?
    A class inheriting from more than one class.

  4. What are class methods and static methods?

  • @classmethod: Takes cls

  • @staticmethod: No self or cls

  1. What is abstraction?
    Hiding implementation and showing only essential features.

๐Ÿ—„๏ธ SQL & DBMS (5 Questions)

  1. What are foreign keys?
    Keys used to link two tables.

  2. Write SQL to find total salary department-wise.

SELECT department, SUM(salary) FROM employees GROUP BY department;
  1. What is ACID in DBMS?
    Atomicity, Consistency, Isolation, Durability โ€“ guarantees for transaction reliability.

  2. Difference between DELETE, TRUNCATE, and DROP?

  • DELETE: Deletes rows (can use WHERE)

  • TRUNCATE: Deletes all rows (faster, no rollback)

  • DROP: Removes entire table

  1. What is a view in SQL?
    A virtual table based on a query.

๐Ÿ“ Aptitude & Logical (5 Questions)

  1. Find missing number: 1, 3, 6, 10, 15, ?
    21 (add 1,2,3,...)

  2. A can do a job in 6 days, B in 8. Working together?
    1/6 + 1/8 = 7/24 โ‡’ Total = 24/7 โ‰ˆ 3.43 days

  3. Speed = 60km/h, Time = 2.5hr. Distance = ?
    150 km

  4. If 2x + 3 = 11, find x.
    x = 4

  5. Odd one out: 2, 4, 6, 8, 9
    9 (odd number)


๐Ÿ–ฅ๏ธ CS Fundamentals (OS, CN) (5 Questions)

  1. What is multiprocessing vs multithreading?
  • Multiprocessing: Uses multiple CPUs

  • Multithreading: Uses multiple threads in same process

  1. What is a socket?
    End-point for network communication between machines.

  2. What is a firewall?
    Network security system that monitors incoming/outgoing traffic.

  3. What is paging in OS?
    Memory management scheme where processes are divided into pages.

  4. What is the difference between static and dynamic IP?

  • Static: Fixed IP

  • Dynamic: Changes each time


๐Ÿง  HR & General (5 Questions)

  1. What are your career goals?
    "To become a skilled Python developer and contribute to impactful projects."

  2. Why should we hire you?
    "I bring strong Python skills, quick learning ability, and team-oriented mindset."

  3. What do you know about Cognizant?
    "A global IT leader known for digital transformation, innovation, and talent development."

  4. What are your hobbies?
    Choose something constructive (e.g., reading tech blogs, coding challenges, etc.)

  5. Do you have any questions for us?
    "Yes, could you tell me more about the career growth and training programs at Cognizant?"



๐Ÿงช MOCK TEST โ€“ PART 1 (QUESTIONS)

๐Ÿ Python & Coding Logic

  1. What will be the output of the following code?

     a = [1, 2, 3]
     b = a
     b.append(4)
     print(a)
    
  2. What is the output of:

     def func(x=[]):
         x.append(1)
         return x
    
     print(func())
     print(func())
    
  3. What does the map() function do in Python?

  4. Predict the output:

     x = 10
     def change(x):
         x += 5
         return x
    
     print(change(x))
     print(x)
    
  5. What does the zip() function return?


๐Ÿ“Š DSA & Algorithm Logic

  1. What is the time complexity of the following?

     for i in range(n):
         for j in range(n):
             print(i, j)
    
  2. Write a Python function to check if a number is prime.

  3. Whatโ€™s the result of set([1, 2, 2, 3, 3])?

  4. Which data structure uses FIFO principle?

  5. Which searching algorithm is more efficient for sorted arrays: Linear or Binary?


๐Ÿ—„๏ธ DBMS & CS Fundamentals

  1. What is the output of this SQL?
SELECT COUNT(*) FROM employees WHERE salary IS NULL;
  1. What is a foreign key?

  2. Which OS component handles CPU scheduling?

  3. Name one protocol used for secure web communication.

  4. What is the difference between stack and heap memory?


โœ… MOCK TEST โ€“ PART 2 (ANSWERS & EXPLANATIONS)

๐Ÿ Python & Coding Logic

  1. Output: [1, 2, 3, 4]
    Because a and b refer to the same list (mutable).

  2. Output:

     [1]
     [1, 1]
    

    Default mutable argument persists between calls.

  3. Answer: map() applies a function to each item of an iterable and returns a map object.

  4. Output:

     15
     10
    

    Because integers are immutable. Original x remains unchanged.

  5. Answer: A zip object (iterator of tuples), pairing elements from multiple iterables.


๐Ÿ“Š DSA & Algorithm Logic

  1. Time Complexity: O(nยฒ) โ€“ Nested loop over n.

  2. Prime Check Function:

     def is_prime(n):
         if n < 2: return False
         for i in range(2, int(n**0.5)+1):
             if n % i == 0: return False
         return True
    
  3. Output: {1, 2, 3} โ€“ set removes duplicates.

  4. Answer: Queue โ€“ First-In First-Out.

  5. Answer: Binary Search (O(log n)) is more efficient for sorted arrays than Linear Search (O(n)).


๐Ÿ—„๏ธ DBMS & CS Fundamentals

  1. Answer: Number of rows with NULL salary.

  2. Answer: A key that references a primary key in another table.

  3. Answer: The CPU Scheduler or Dispatcher.

  4. Answer: HTTPS (uses SSL/TLS).

  5. Answer:

  • Stack: Stores function calls, has limited space, managed by compiler.

  • Heap: Stores dynamic memory, managed manually or with GC.



โœ… ๐—Ÿ๐—ฎ๐˜€๐˜-๐— ๐—ถ๐—ป๐˜‚๐˜๐—ฒ ๐—ฅ๐—ฒ๐˜ƒ๐—ถ๐˜€๐—ถ๐—ผ๐—ป ๐—ง๐—ถ๐—ฝ๐˜€ (Python + CS)

๐Ÿ Python

  1. Data Types & Conversions:
    Revise list, dict, tuple, set, str, int, float, and how to convert between them.

  2. Functions & Scope:
    Understand def, lambda, *args, **kwargs, closures, and nonlocal/global.

  3. OOP in Python:
    Focus on class, inheritance, __init__, method overriding, and decorators like @staticmethod.

  4. File Handling:
    Practice reading/writing using with open() and handling file exceptions.

  5. Common Errors:
    Know how to interpret and fix TypeError, KeyError, IndexError, and ValueError.

  6. Built-in Functions:
    Revise map(), filter(), zip(), enumerate(), sorted(), reversed().


๐Ÿ“Š DSA (Python-Based)

  • Sorting (Bubble, Insertion, Quick) โ€“ Focus on time complexities.

  • Searching (Linear, Binary) โ€“ Write 3โ€“5 lines max for binary search.

  • Recursion โ€“ Write recursive factorial, Fibonacci, and reverse string.

  • Hashing & Sets โ€“ Use sets to remove duplicates or check intersections.

  • Stack/Queue โ€“ Implement with list or collections.deque.


๐Ÿ—„๏ธ SQL + DBMS

  • SQL Queries:
    SELECT, JOIN, GROUP BY, HAVING, ORDER BY, LIMIT, COUNT(), NULL.

  • ACID Properties & Keys:
    Focus on Primary, Foreign, Composite Keys, and normalization levels.


๐Ÿง  OS + CN (Basic)

  • Learn basic differences:

    • Process vs Thread

    • TCP vs UDP

    • RAM vs Cache

    • Paging vs Segmentation

    • Firewall, IP Address, DNS



Python + DSA + SQL One-Page Cheat Sheet

Python Core

- Data Types: int, float, str, list, tuple, dict, set, bool, NoneType

- List Methods: append(), extend(), pop(), remove(), sort(), reverse()

- String Methods: split(), join(), strip(), lower(), upper(), find(), replace()

- Looping: for, while; Use range(), enumerate(), zip()

- Functions: def, lambda, args, *kwargs, return

- OOP: class, init, self, inheritance, @staticmethod, @classmethod

- Exception Handling: try, except, else, finally, raise

- File I/O: with open('file.txt', 'r') as f: data = f.read()

- Useful Built-ins: map(), filter(), reduce(), sorted(), any(), all()

DSA Time Complexities & Patterns

- Linear Search: O(n), Binary Search: O(log n) [sorted array]

- Sorting: Bubble (O(n^2)), Merge (O(n log n)), Quick (Avg: O(n log n))

- Recursion: Base case + recursive case (e.g. factorial, Fibonacci)

- Hashing: Use dict/set for O(1) lookup

- Stack/Queue: Use list or collections.deque

- Linked List: Node class with next pointer; Traverse with while

- Tree Traversals: Inorder, Preorder, Postorder (use recursion)

- Fibonacci (Memo): @lru_cache from functools

- Sliding Window, Two Pointers: Used for subarrays and strings

SQL Essentials

- SELECT FROM table;

- WHERE clause: SELECT FROM emp WHERE salary > 50000;

- GROUP BY + HAVING: GROUP BY dept HAVING COUNT(*) > 2;

- JOINS: INNER, LEFT, RIGHT, FULL OUTER JOIN

- Aggregate: COUNT(), SUM(), AVG(), MAX(), MIN()

- ORDER BY column ASC/DESC;

- LIMIT n OFFSET m;

- NULL check: IS NULL / IS NOT NULL

- Keys: PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL

- Transactions: COMMIT, ROLLBACK, ACID properties

0
Subscribe to my newsletter

Read articles from Athuluri Akhil directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Athuluri Akhil
Athuluri Akhil