0% found this document useful (0 votes)
0 views26 pages

Programming Concepts Level Pseudocode Questions file 2

Good

Uploaded by

abhay sharma
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)
0 views26 pages

Programming Concepts Level Pseudocode Questions file 2

Good

Uploaded by

abhay sharma
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

PROGRAMMING CONCEPTS

LEVEL PSEUDOCODE
QUESTIONS – COMPANY
ASKED
Fundamental Programming Concepts Tested in IT Companies
Programming Concepts Covered:
1. Object-Oriented Concepts: Inheritance, Polymorphism,
Encapsulation, Abstraction
2. Advanced OOP: Virtual functions, Abstract classes, Interfaces
3. Design Patterns: Singleton, Factory, Observer, Dependency
Injection
4. Generic Programming: Templates, Specialization
5. Concurrency: Threading, Synchronization
6. Memory Management: RAII, Constructors, Destructors

Company-Specific Advanced Focus:


1. Product Companies (Google, Amazon, Microsoft): Advanced
concepts like generics, closures, threading
2. Fintech Companies (Razorpay, PhonePe, Paytm): Design
patterns and clean architecture
3. E-commerce (Flipkart, Snapdeal): OOP concepts and system
design
4. Mobility (Ola, Uber): Factory patterns and abstraction
5. Food Tech (Zomato, Swiggy): Event handling and dependency
injection
Concepts:
1. Object-Oriented Programming:
o Inheritance & Method Overriding
o Encapsulation & Access Modifiers
o Abstract Classes & Interfaces
o Constructor/Destructor Lifecycle
o Virtual Functions & Dynamic Dispatch
2. Design Patterns:
o Singleton Pattern
o Factory Pattern
o Observer Pattern (Event Handling)
o Dependency Injection
o Method Chaining (Fluent Interface)
3. Advanced Language Features:
o Generic Programming & Templates
o Template Specialization
o Operator Overloading
o Closures & Function Scope
o Pointer Arithmetic
4. System Programming Concepts:
o Thread Synchronization & Mutex
o Exception Propagation & Finally Blocks
o Memory Management (RAII Pattern)
o Composition vs Inheritance
Question 1 (Accenture ASE - 2024)
What will this inheritance pseudocode output?

ALGORITHM inheritance_concept
BEGIN
CLASS Animal
name = ""

FUNCTION make_sound()
RETURN "Some generic sound"
END
END CLASS

CLASS Dog EXTENDS Animal


FUNCTION make_sound()
RETURN "Woof!"
END
END CLASS

animal = NEW Animal()


dog = NEW Dog()
[Link] = "Generic"
[Link] = "Buddy"

PRINT [Link] + ": " + animal.make_sound()


PRINT [Link] + ": " + dog.make_sound()
END

Options:

A) Generic: Some generic sound, Buddy: Woof!


B) Generic: Some generic sound, Buddy: Some generic sound
C) Error - inheritance not properly defined
D) Both print "Some generic sound"
Question 2 (IBM India - 2024)
What does this pointer arithmetic pseudocode demonstrate?

ALGORITHM pointer_arithmetic
BEGIN
arr = [10, 20, 30, 40, 50]
ptr = ADDRESS_OF(arr[0])

PRINT VALUE_AT(ptr)
ptr = ptr + 2 // Move pointer by 2 positions
PRINT VALUE_AT(ptr)

ptr = ptr - 1 // Move back by 1 position


PRINT VALUE_AT(ptr)
END

Options:

A) 10 30 20
B) 10 20 30
C) 0 2 1
D) Undefined behavior
Question 3 (Deloitte USI - 2023)
What will be the output of this encapsulation pseudocode?

ALGORITHM encapsulation_demo
BEGIN
CLASS BankAccount
PRIVATE balance = 0

PUBLIC FUNCTION deposit(amount)


IF amount > 0 THEN
balance = balance + amount
RETURN TRUE
END IF
RETURN FALSE
END

PUBLIC FUNCTION get_balance()


RETURN balance
END

PRIVATE FUNCTION calculate_interest()


RETURN balance * 0.05
END
END CLASS

account = NEW BankAccount()


[Link](1000)
PRINT account.get_balance()

// [Link] = 2000 // This would cause error


// account.calculate_interest() // This would cause error
END

Options:

A) 1000
B) 1050
C) Error - private members accessed
D) 0
Question 4 (Oracle India - 2024)
What concept does this constructor pseudocode illustrate?

ALGORITHM constructor_concept
BEGIN
CLASS Student
name = ""
age = 0
grade = ""

CONSTRUCTOR Student()
name = "Unknown"
age = 0
grade = "Not Assigned"
END

CONSTRUCTOR Student(n, a)
name = n
age = a
grade = "Not Assigned"
END

CONSTRUCTOR Student(n, a, g)
name = n
age = a
grade = g
END
END CLASS
student1 = NEW Student()
student2 = NEW Student("John", 20)
student3 = NEW Student("Alice", 22, "A")
PRINT [Link] + " " + [Link] + " " + [Link]
END

Options:

A) Constructor overloading
B) Constructor chaining
C) Default initialization
D) Parameterized constructor
Question 5 (Microsoft India - 2023)
What will this multithreading pseudocode output?

ALGORITHM threading_concept
BEGIN
shared_counter = 0
THREAD thread1()
BEGIN
FOR i = 1 TO 3
LOCK mutex
temp = shared_counter
temp = temp + 1
shared_counter = temp
PRINT "Thread1: " + shared_counter
UNLOCK mutex
END FOR
END
THREAD thread2()
BEGIN
FOR i = 1 TO 2
LOCK mutex
temp = shared_counter
temp = temp + 2
shared_counter = temp
PRINT "Thread2: " + shared_counter
UNLOCK mutex
END FOR
END
START thread1()
START thread2()
WAIT FOR ALL THREADS
PRINT "Final: " + shared_counter
END

Options:

A) Final counter value will always be 7


B) Final counter value depends on thread execution order
C) Deadlock will occur
D) Race condition will occur
Question 6 (Amazon India - 2024)
What does this generic programming pseudocode demonstrate?

ALGORITHM generic_programming
BEGIN
GENERIC CLASS Stack<T>
items = []
top = -1

FUNCTION push(item OF TYPE T)


top = top + 1
items[top] = item
END

FUNCTION pop() RETURNS T


IF top >= 0 THEN
item = items[top]
top = top - 1
RETURN item
END IF
RETURN NULL
END
END CLASS

int_stack = NEW Stack<INTEGER>()


string_stack = NEW Stack<STRING>()

int_stack.push(10)
string_stack.push("Hello")

PRINT int_stack.pop()
PRINT string_stack.pop()
END

Options:

A) Generic/Template programming
B) Function overloading
C) Inheritance
D) Polymorphism
Question 7 (Google India - 2023)
What will this lambda/closure pseudocode output?

ALGORITHM closure_concept
BEGIN
FUNCTION outer_function(x)
BEGIN
FUNCTION inner_function(y)
BEGIN
RETURN x + y
END

RETURN inner_function
END

add_five = outer_function(5)
add_ten = outer_function(10)

result1 = add_five(3)
result2 = add_ten(7)

PRINT result1 + " " + result2


END

Options:

A) 8 17
B) 5 10
C) 3 7
D) Error - nested functions not allowed
Question 8 (Tata Elxsi - 2024)
What concept does this destructor pseudocode show?

ALGORITHM destructor_concept
BEGIN
CLASS FileHandler
filename = ""
file_pointer = NULL

CONSTRUCTOR FileHandler(name)
filename = name
file_pointer = OPEN_FILE(filename)
PRINT "File opened: " + filename
END

DESTRUCTOR ~FileHandler()
IF file_pointer != NULL THEN
CLOSE_FILE(file_pointer)
PRINT "File closed: " + filename
END IF
END
END CLASS

BEGIN SCOPE
handler = NEW FileHandler("[Link]")
// Some file operations
END SCOPE // handler goes out of scope here

PRINT "Program continues"


END

Options:

A) Constructor and Destructor lifecycle


B) File handling operations
C) Memory management
D) Exception handling
Question 9 (Flipkart - 2024)
What will this operator overloading pseudocode output?

ALGORITHM operator_overloading
BEGIN
CLASS Complex
real = 0
imaginary = 0

CONSTRUCTOR Complex(r, i)
real = r
imaginary = i
END

OPERATOR + (other)
result_real = real + [Link]
result_imag = imaginary + [Link]
RETURN NEW Complex(result_real, result_imag)
END

FUNCTION display()
RETURN real + " + " + imaginary + "i"
END
END CLASS

c1 = NEW Complex(3, 4)
c2 = NEW Complex(1, 2)
c3 = c1 + c2

PRINT [Link]()
END

Options: A) 4 + 6i
B) 3 + 4i
C) 1 + 2i
D) Error - operator overloading invalid
Question 10 (Paytm - 2023)
What does this interface implementation pseudocode demonstrate?

ALGORITHM interface_concept
BEGIN
INTERFACE Drawable
FUNCTION draw()
FUNCTION get_area()
END INTERFACE

CLASS Circle IMPLEMENTS Drawable


radius = 0

CONSTRUCTOR Circle(r)
radius = r
END

FUNCTION draw()
RETURN "Drawing a circle"
END

FUNCTION get_area()
RETURN 3.14 * radius * radius
END
END CLASS

CLASS Rectangle IMPLEMENTS Drawable


width = 0
height = 0

CONSTRUCTOR Rectangle(w, h)
width = w
height = h
END

FUNCTION draw()
RETURN "Drawing a rectangle"
END
FUNCTION get_area()
RETURN width * height
END
END CLASS

shapes = [NEW Circle(5), NEW Rectangle(4, 6)]

FOR each shape IN shapes


PRINT [Link]() + ", Area: " + shape.get_area()
END FOR
END

Options:

A) Interface implementation and polymorphism


B) Abstract class inheritance
C) Method overloading
D) Encapsulation
Question 11 (Zomato - 2024)
What will this event handling pseudocode output?

ALGORITHM event_handling
BEGIN
CLASS Button
click_handlers = []

FUNCTION add_click_handler(handler)
ADD handler TO click_handlers
END

FUNCTION click()
FOR each handler IN click_handlers
handler.handle_click()
END FOR
END
END CLASS
CLASS AlertHandler
message = ""
CONSTRUCTOR AlertHandler(msg)
message = msg
END
FUNCTION handle_click()
PRINT "Alert: " + message
END
END CLASS
button = NEW Button()
handler1 = NEW AlertHandler("First click!")
handler2 = NEW AlertHandler("Second click!")
button.add_click_handler(handler1)
button.add_click_handler(handler2)
[Link]()
END

Options:

A) Alert: First click! Alert: Second click!


B) Alert: Second click!
C) Alert: First click!
D) No output
Question 12 (Swiggy - 2023)
What concept does this dependency injection pseudocode show?

ALGORITHM dependency_injection
BEGIN
INTERFACE Logger
FUNCTION log(message)
END INTERFACE

CLASS FileLogger IMPLEMENTS Logger


FUNCTION log(message)
PRINT "File: " + message
END
END CLASS

CLASS ConsoleLogger IMPLEMENTS Logger


FUNCTION log(message)
PRINT "Console: " + message
END
END CLASS

CLASS OrderService
logger = NULL

CONSTRUCTOR OrderService(log_service)
logger = log_service
END

FUNCTION create_order()
[Link]("Order created successfully")
END
END CLASS

file_logger = NEW FileLogger()


console_logger = NEW ConsoleLogger()

service1 = NEW OrderService(file_logger)


service2 = NEW OrderService(console_logger)
service1.create_order()
service2.create_order()
END

Options:

A) Dependency Injection pattern


B) Factory pattern
C) Singleton pattern
D) Observer pattern
Question 13 (BYJU'S - 2024)
What will this singleton pattern pseudocode output?

ALGORITHM singleton_pattern
BEGIN
CLASS DatabaseConnection
STATIC instance = NULL
connection_id = 0

PRIVATE CONSTRUCTOR DatabaseConnection()


connection_id = RANDOM_NUMBER(1000, 9999)
PRINT "Creating connection: " + connection_id
END

STATIC FUNCTION get_instance()


IF instance = NULL THEN
instance = NEW DatabaseConnection()
END IF
RETURN instance
END

FUNCTION get_connection_id()
RETURN connection_id
END
END CLASS

conn1 = DatabaseConnection.get_instance()
conn2 = DatabaseConnection.get_instance()

PRINT "Connection 1 ID: " + conn1.get_connection_id()


PRINT "Connection 2 ID: " + conn2.get_connection_id()
PRINT "Same instance: " + (conn1 = conn2)
END

Options:

A) Two different connection IDs, Same instance: false


B) Same connection ID, Same instance: true
C) Error - private constructor
D) Two different connection IDs, Same instance: true
Question 14 (Ola - 2023)
What does this factory pattern pseudocode demonstrate?

ALGORITHM factory_pattern
BEGIN
INTERFACE Vehicle
FUNCTION start()
FUNCTION stop()
END INTERFACE

CLASS Car IMPLEMENTS Vehicle


FUNCTION start()
RETURN "Car engine started"
END

FUNCTION stop()
RETURN "Car engine stopped"
END
END CLASS

CLASS Bike IMPLEMENTS Vehicle


FUNCTION start()
RETURN "Bike engine started"
END

FUNCTION stop()
RETURN "Bike engine stopped"
END
END CLASS

CLASS VehicleFactory
STATIC FUNCTION create_vehicle(type)
IF type = "car" THEN
RETURN NEW Car()
ELSE IF type = "bike" THEN
RETURN NEW Bike()
END IF
RETURN NULL
END
END CLASS

vehicle1 = VehicleFactory.create_vehicle("car")
vehicle2 = VehicleFactory.create_vehicle("bike")

PRINT [Link]()
PRINT [Link]()
END

Options:

A) Factory design pattern


B) Abstract factory pattern
C) Builder pattern
D) Prototype pattern
Question 15 (Uber - 2024)
What will this abstract class pseudocode output?

ALGORITHM abstract_class
BEGIN
ABSTRACT CLASS Shape
color = "white"

ABSTRACT FUNCTION calculate_area()

FUNCTION set_color(c)
color = c
END

FUNCTION display_info()
RETURN "Shape color: " + color + ", Area: " + calculate_area()
END
END CLASS

CLASS Circle EXTENDS Shape


radius = 0

CONSTRUCTOR Circle(r)
radius = r
END

FUNCTION calculate_area()
RETURN 3.14 * radius * radius
END
END CLASS

circle = NEW Circle(5)


circle.set_color("red")
PRINT circle.display_info()
END

Options: A) Shape color: red, Area: 78.5


B) Shape color: white, Area: 78.5
C) Error - abstract class instantiation
D) Shape color: red, Area: 0
Question 16 (Razorpay - 2023)
What concept does this method chaining pseudocode show?

ALGORITHM method_chaining
BEGIN
CLASS StringBuilder
content = ""

FUNCTION append(text)
content = content + text
RETURN this
END

FUNCTION append_line(text)
content = content + text + "\n"
RETURN this
END

FUNCTION to_string()
RETURN content
END
END CLASS

builder = NEW StringBuilder()


result = builder
.append("Hello ")
.append("World")
.append_line("!")
.append("How ")
.append("are you?")
.to_string()

PRINT result
END

Options: A) Method chaining (Fluent interface)


B) Builder pattern
C) Decorator pattern
D) Chain of responsibility
Question 17 (PhonePe - 2024)
What will this exception propagation pseudocode output?

ALGORITHM exception_propagation
BEGIN
FUNCTION level3()
BEGIN
THROW NEW Exception("Error in level 3")
END

FUNCTION level2()
BEGIN
TRY
level3()
CATCH Exception e
PRINT "Caught in level 2: " + [Link]
THROW e // Re-throw the exception
END TRY
END

FUNCTION level1()
BEGIN
TRY
level2()
CATCH Exception e
PRINT "Caught in level 1: " + [Link]
FINALLY
PRINT "Level 1 cleanup"
END TRY
END

level1()
PRINT "Program continues"
END

Options: A) Caught in level 2: Error in level 3, Caught in level 1: Error in level 3, Level 1
cleanup, Program continues
B) Caught in level 2: Error in level 3, Level 1 cleanup, Program continues
C) Error in level 3, Program terminates
D) Caught in level 1: Error in level 3, Program continues
Question 18 (Flipkart Myntra - 2023)
What does this composition vs inheritance pseudocode demonstrate?

ALGORITHM composition_vs_inheritance
BEGIN
CLASS Engine
horsepower = 0

CONSTRUCTOR Engine(hp)
horsepower = hp
END

FUNCTION start()
RETURN "Engine with " + horsepower + "HP started"
END
END CLASS

CLASS Car
engine = NULL
brand = ""

CONSTRUCTOR Car(b, engine_hp)


brand = b
engine = NEW Engine(engine_hp)
END

FUNCTION start_car()
RETURN brand + " car: " + [Link]()
END
END CLASS

my_car = NEW Car("Toyota", 150)


PRINT my_car.start_car()
END

Options: A) Composition relationship


B) Inheritance relationship
C) Aggregation relationship
D) Association relationship
Question 19 (Snapdeal - 2024)
What will this virtual function pseudocode output?

ALGORITHM virtual_functions
BEGIN
CLASS Animal
VIRTUAL FUNCTION make_sound()
RETURN "Generic animal sound"
END

FUNCTION describe()
RETURN "This animal makes: " + make_sound()
END
END CLASS

CLASS Dog EXTENDS Animal


FUNCTION make_sound() // Override virtual function
RETURN "Woof!"
END
END CLASS

CLASS Cat EXTENDS Animal


FUNCTION make_sound() // Override virtual function
RETURN "Meow!"
END
END CLASS

animals = [NEW Animal(), NEW Dog(), NEW Cat()]

FOR each animal IN animals


PRINT [Link]()
END FOR
END

Options: A) This animal makes: Generic animal sound, This animal makes: Woof!, This
animal makes: Meow!
B) All print: This animal makes: Generic animal sound
C) This animal makes: Woof!, This animal makes: Woof!, This animal makes: Woof!
D) Error - virtual functions not supported
Question 20 (InMobi - 2023)
What concept does this template specialization pseudocode show?

ALGORITHM template_specialization
BEGIN
GENERIC CLASS Printer<T>
FUNCTION print(value OF TYPE T)
RETURN "Generic: " + CONVERT_TO_STRING(value)
END
END CLASS

// Template specialization for STRING type


SPECIALIZED CLASS Printer<STRING>
FUNCTION print(value OF TYPE STRING)
RETURN "String: \"" + value + "\""
END
END CLASS

// Template specialization for INTEGER type


SPECIALIZED CLASS Printer<INTEGER>
FUNCTION print(value OF TYPE INTEGER)
RETURN "Integer: " + value + " (base 10)"
END
END CLASS

int_printer = NEW Printer<INTEGER>()


string_printer = NEW Printer<STRING>()
float_printer = NEW Printer<FLOAT>()

PRINT int_printer.print(42)
PRINT string_printer.print("Hello")
PRINT float_printer.print(3.14)
END

Options: A) Template/Generic specialization


B) Function overloading
C) Method overriding
D) Polymorphism

You might also like