Coding Projects
67.9K subscribers
945 photos
2 videos
266 files
577 links
Channel specialized for advanced concepts and projects to master:
* Python programming
* Web development
* Java programming
* Artificial Intelligence
* Machine Learning

Managed by: @love_data
Download Telegram
๐ŸŽ“ ๐—›๐—”๐—ฅ๐—ฉ๐—”๐—ฅ๐—— ๐—จ๐—ก๐—œ๐—ฉ๐—˜๐—ฅ๐—ฆ๐—œ๐—ง๐—ฌ ๐—™๐—ฅ๐—˜๐—˜ ๐—ข๐—ก๐—Ÿ๐—œ๐—ก๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐Ÿ˜

Dreaming of learning from one of the worldโ€™s most prestigious universities? Explore Harvardโ€™s online courses and build valuable, career-ready skills from home!

๐Ÿ’ก Beginner-friendly options
โฐ Learn at your own pace
๐ŸŒ Accessible online worldwide
๐ŸŽฏ Ideal for students, freshers and working professionals

๐Ÿ”— ๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ฒ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐Ÿ‘‡

https://pdlink.in/4xPUdzU

๐Ÿ“ข Share this valuable opportunity with your friends and classmates!
โค2
๐Ÿ”€ Now, let's Understand Conditional Statements ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ”ฅ

After variables, data types, and operators, the next important concept is conditional statements.

Conditional statements allow a program to make decisions based on whether something is true or false.

For example:

If the temperature is high โ†’ turn on the fan.

Otherwise โ†’ keep it off.

This type of decision-making is used in almost every real-world application.

๐Ÿง  1. What is a Condition?

A condition is an expression that produces a Boolean result: True or False

Example:
age = 20
age >= 18

The result is: True because 20 is greater than or equal to 18.

๐Ÿ 2. The "if" Statement

The if statement executes a block of code when a condition is true.
age = 20

if age >= 18:
    print("Eligible")

Since the condition is true, the message is displayed.

๐Ÿ”„ 3. The "if-else" Statement

Sometimes we need to handle both possibilities.
age = 16

if age >= 18:
    print("Eligible")
else:
    print("Not eligible")

Here, the condition is false, so the else block runs.

๐Ÿงฉ 4. The "if-elif-else" Statement

When there are multiple possible conditions, we can use elif.
marks = 75

if marks >= 90:
    print("Excellent")
elif marks >= 60:
    print("Good")
else:
    print("Needs improvement")

Python checks the conditions from top to bottom. Once it finds a true condition, its corresponding block is executed.

๐Ÿ”— 5. Multiple Conditions

Logical operators can be used to combine conditions.
age = 25
has_ticket = True

if age >= 18 and has_ticket:
    print("Entry allowed")

Both conditions must be true because and is being used.

โŒ 6. Using "not"

The not operator reverses a Boolean condition.
is_blocked = False

if not is_blocked:
    print("Access allowed")

Since is_blocked is False, not is_blocked becomes True.

๐ŸŒ 7. Conditional Statements in Different Languages

The concept is similar across programming languages, although the syntax changes.

Python
if age >= 18:
    print("Adult")

JavaScript
if (age >= 18) {
    console.log("Adult");
}

Java
if (age >= 18) {
    System.out.println("Adult");
}

C++
if (age >= 18) {
    cout << "Adult";
}

The fundamental idea remains the same: evaluate a condition and decide what code should execute.

๐Ÿฆ 8. Real-World Uses

Conditional statements are used everywhere:

โœ” Login authentication

โœ” ATM transactions

โœ” Online shopping

โœ” Age verification

โœ” Payment processing

โœ” Game logic

โœ” Form validation

โœ” Access control

โœ” Recommendation systems 

For example, an online store might check whether Stock is available before allowing a customer to place an order.

โš ๏ธ 9. Common Beginner Mistake

Don't confuse assignment with comparison.
x = 10

means: Assign 10 to x.

While:
x == 10

means: Check whether x is equal to 10.

This difference is extremely important when writing conditions.

๐Ÿง  Conditional statements allow programs to move beyond simply executing instructions in sequence. They allow programs to make decisions.

Double Tap โค๏ธ For More
โค9๐Ÿ”ฅ1๐Ÿ˜1
๐—™๐—ฅ๐—˜๐—˜ ๐—ฅ๐—ฒ๐˜€๐—ผ๐˜‚๐—ฟ๐—ฐ๐—ฒ๐˜€ ๐—ง๐—ผ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป ๐—”๐—œ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ๐Ÿš€
โ€‹
Explore 6 free resources covering AI fundamentals, tools, deep learning, research and real-world applications.

โœ… 100% Free Learning
โœ… Beginner-Friendly
โœ… AI โ€ข ML โ€ข Deep Learning
โœ… Real-World Applications

๐Ÿ”— ๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ฒ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐Ÿ‘‡

https://pdlink.in/4AFHq5R

๐Ÿ“ข Share this valuable opportunity with your friends and classmates!
What will be the output?
age = 20
if age >= 18: print("Adult") else: print("Minor")
Anonymous Quiz
86%
Adult
14%
Minor
๐Ÿ‘3
What will be the output?
x = 10

if x > 5 and x < 10:
print("Yes")
else:
print("No")


A) Yes โค๏ธ
B) No ๐Ÿ‘
๐Ÿ‘83โค10
What will be the output?
marks = 85
if marks >= 90: print("A") elif marks >= 80: print("B") else: print("C")
Anonymous Quiz
18%
A
73%
B
9%
C
What will be the output?
x = 5
if not x > 10: print("Yes") else: print("No")
Anonymous Quiz
58%
Yes
42%
No
What will be the output?
x = 15
if x > 10: if x < 20: print("A") else: print("B") else: print("C")
Anonymous Quiz
64%
A
23%
B
13%
C
โค4๐Ÿ”ฅ1
๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—•๐—œ ๐—ณ๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜! ๐Ÿ”ฅ

Learn Power BI through these FREE learning resources
โ€‹
โœจ What You'll Learn:
๐Ÿ“Š Interactive Dashboards
๐Ÿ“ˆ Data Visualization
๐Ÿงน Data Transformation
๐Ÿ’ผ Real-World Reporting Skills
๐ŸŽฏ Beginner-Friendly โ€” No Coding Required

๐—ฆ๐˜๐—ฎ๐—ฟ๐˜ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด ๐—ณ๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜
โ€‹
โ€‹https://pdlink.in/4hznwlu

๐Ÿ’ซPerfect for Students โ€ข Freshers โ€ข Data Analyst Aspirants โ€ข Working Professionals
โค3
๐Ÿš€๐—ฃ๐—ฎ๐˜† ๐—”๐—ณ๐˜๐—ฒ๐—ฟ ๐—ฃ๐—น๐—ฎ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ง๐—ฟ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด | ๐—•๐—ฒ๐—ฐ๐—ผ๐—บ๐—ฒ ๐—ฎ ๐—™๐˜‚๐—น๐—น๐˜€๐˜๐—ฎ๐—ฐ๐—ธ ๐——๐—ฒ๐˜ƒ๐—ฒ๐—น๐—ผ๐—ฝ๐—ฒ๐—ฟ ๐—ช๐—œ๐˜๐—ต ๐—š๐—ฒ๐—ป๐—”๐—œ

Start a high-paying tech careerโ€”even without prior coding experience

๐Ÿ† ๐—ฃ๐—น๐—ฎ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—›๐—ถ๐—ด๐—ต๐—น๐—ถ๐—ด๐—ต๐˜๐˜€:
๐Ÿ’ฐ โ‚น41 LPA highest salary
๐Ÿ“ˆ โ‚น7.4 LPA average salary
๐ŸŽ“ 2,000+ students placed
๐Ÿข 500+ hiring partners
โœ… 100% job assistance
๐Ÿ“œ Skill Indiaโ€“authenticated certificate

๐Ÿ”— ๐—”๐—ฝ๐—ฝ๐—น๐˜† ๐—ก๐—ผ๐˜„๐Ÿ‘‡:-

https://pdlink.in/3SuUeuD

๐ŸŽฏ HurryUp.....Limited Seats Available
โค1๐Ÿ”ฅ1
๐ŸงฉNow, Let's Understand Functions in Programming ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ”ฅ

After variables, operators, conditions, and loops, the next important concept is functions.

Functions help you organize code, avoid repetition, and make programs easier to understand and maintain.

๐Ÿง  1. What is a Function?

A function is a reusable block of code designed to perform a specific task.

Instead of writing the same code repeatedly, you can put it inside a function and call it whenever you need it.

For example:
def greet():
    print("Hello!")

greet()

Output:
Hello!

๐ŸŽฏ 2. Why Do We Use Functions?

Functions help with:

โœ” Code reusability

โœ” Better organization

โœ” Easier debugging

โœ” Readability

โœ” Maintaining large programs 

A good function usually focuses on one clear task.

๐Ÿ“ฅ 3. Function Parameters

Functions can accept information from the code that calls them.
def greet(name):
    print("Hello", name)

greet("Alex")

Output:
Hello Alex

Here, "name" is a parameter.

"Alex" is the argument passed to the function.

๐Ÿ“ค 4. Returning a Value

A function can return a result instead of directly displaying it.
def add(a, b):
    return a + b

result = add(10, 5)
print(result)

Output:
15

"return" sends the result back to the place where the function was called.

๐Ÿ”„ 5. Parameters vs Arguments

These two terms are often confused.

In:
def add(a, b):
    return a + b

"a" and "b" are parameters.

In:
add(10, 5)

"10" and "5" are arguments.

Parameter โ†’ Variable defined by the function

Argument โ†’ Actual value passed to the function 

โš™๏ธ 6. Default Parameters

A function can have a default value for a parameter.
def greet(name="Guest"):
    print("Hello", name)

greet()
greet("Alex")

Output:
Hello Guest
Hello Alex

If no argument is provided, the default value is used.

๐ŸŒ 7. Functions in Different Languages

The syntax changes between languages, but the concept remains similar.

Python
def add(a, b):
    return a + b

JavaScript
function add(a, b) {
    return a + b;
}

Java
static int add(int a, int b) {
    return a + b;
}

C++
int add(int a, int b) {
    return a + b;
}

The purpose is the same: define reusable logic that can be called when needed.

๐Ÿง  8. Local Variables

A variable created inside a function is generally local to that function.
def calculate():
    result = 100
    print(result)

calculate()

Here, "result" belongs to the function's local scope.

Understanding scope becomes especially important as programs become larger.

๐Ÿ” 9. Functions Can Call Other Functions

One function can use another function.
def add(a, b):
    return a + b

def show_result():
    result = add(10, 20)
    print(result)

show_result()

This allows larger programs to be broken into smaller, manageable pieces.

๐Ÿงฉ 10. Functions and Loops

Functions and loops are often used together.
def print_numbers():
    for i in range(1, 6):
        print(i)

print_numbers()

The function organizes the task, while the loop handles repetition.

๐Ÿ”ฅ Double Tap โค๏ธ For More
โค14
๐ŸŽ“ ๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ผ๐—ณ๐˜ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ๐˜€! ๐Ÿš€๐Ÿ”ฅ

Upgrade your resume with Microsoft learning opportunities. Explore courses covering some of today's most in-demand tech skills!

๐ŸŽฏ Perfect for Students โ€ข Freshers โ€ข Job Seekers โ€ข Working Professionals

โœ… Learn at your own pace โœ… Build career-relevant skills โœ… Explore available certificates and credentials

๐Ÿ”— ๐—”๐—ฐ๐—ฐ๐—ฒ๐˜€๐˜€ ๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ผ๐—ณ๐˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐—›๐—ฒ๐—ฟ๐—ฒ ๐Ÿ‘‡

https://pdlink.in/3Uf5trR

๐Ÿ”ฅ Share with friends looking to upskill in 2026!
๐Ÿ‡ฎ๐Ÿ‡ณ ๐—š๐—ข๐—ฉ๐—˜๐—ฅ๐—ก๐— ๐—˜๐—ก๐—ง ๐—ข๐—™ ๐—œ๐—ก๐——๐—œ๐—” โ€” ๐—”๐—œ๐—–๐—ง๐—˜ ๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ก๐—ฆ๐—›๐—œ๐—ฃ๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ ๐Ÿš€

Students and freshers can explore internship opportunities through the AICTE Internship Portal across multiple domains:

๐Ÿ’ป AI, Data Science & Web Development
๐Ÿ“ˆ Digital Marketing & Business Development
๐Ÿ’ฐ Finance & Accounting
โœ๏ธ Content Writing & Graphic Design
โš™๏ธ Mechanical, Civil & Electrical Engineering

๐Ÿ”— ๐—–๐—ต๐—ฒ๐—ฐ๐—ธ ๐—ข๐—ฝ๐—ฝ๐—ผ๐—ฟ๐˜๐˜‚๐—ป๐—ถ๐˜๐—ถ๐—ฒ๐˜€ & ๐—”๐—ฝ๐—ฝ๐—น๐˜† ๐Ÿ‘‡

https://pdlink.in/4y3vcBl

๐Ÿ“ข Share this opportunity with your friends and classmates!
โค2
๐Ÿš€ ๐—ช๐—ต๐—ถ๐—ฐ๐—ต ๐—ง๐—ฒ๐—ฐ๐—ต ๐—ฆ๐—ธ๐—ถ๐—น๐—น ๐—ช๐—ถ๐—น๐—น ๐—ฌ๐—ผ๐˜‚ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ?

Want to build apps, uncover insights, or create AI solutions? Explore certification courses that match your career goals! ๐ŸŽฏ

๐Ÿ’ป ๐—™๐˜‚๐—น๐—น ๐—ฆ๐˜๐—ฎ๐—ฐ๐—ธ ๐——๐—ฒ๐˜ƒ๐—ฒ๐—น๐—ผ๐—ฝ๐—บ๐—ฒ๐—ป๐˜
๐Ÿ‘‰ https://pdlink.in/3SuUeuD

๐Ÿ“Š ๐——๐—ฎ๐˜๐—ฎ ๐—”๐—ป๐—ฎ๐—น๐˜†๐˜๐—ถ๐—ฐ๐˜€
๐Ÿ‘‰ https://pdlink.in/45vk5ph

๐Ÿ’ซ๐—”๐—œ ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ๐—ถ๐—ป๐—ด
๐Ÿ‘‰ https://pdlink.in/4fWJVID

๐Ÿ”ฅ Choose your path, sharpen your skills, and take the next step towards your tech career!

๐Ÿ“Œ Save this post & share it with a friend planning to upskill.
๐—ง๐—ข๐—ฃ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐—ง๐—ข ๐—•๐—ข๐—ข๐—ฆ๐—ง ๐—ฌ๐—ข๐—จ๐—ฅ ๐—ฆ๐—ž๐—œ๐—Ÿ๐—Ÿ๐—ฆ ๐—œ๐—ก ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ!

Explore FREE online learning resources to develop in-demand skills and improve your career opportunities!

๐ŸŽ“ Why Explore These Courses?
โœ… Learn valuable professional skills
โœ… Improve your resume
โœ… Build practical knowledge
โœ… Learn at your own pace

๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ฒ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐—›๐—ฒ๐—ฟ๐—ฒ๐Ÿ‘‡

https://pdlink.in/3VBdt6V

๐Ÿ’ก Learn New Skills โ†’ Build Confidence โ†’ Unlock Career Opportunities!
๐——๐—ฎ๐˜๐—ฎ ๐˜€๐—ฐ๐—ถ๐—ฒ๐—ป๐—ฐ๐—ฒ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ช๐—ถ๐˜๐—ต ๐—”๐—œ๐Ÿ˜

Future Ready Data Science and AI Skills You Build

->Build Python, Machine Learning, and AI Skills
->Get Mentored by Industry Experts
->Practice with Mock Interviews
->Ace Your Placements & Land Dream Tech Job

๐Ÿค 500+ Partner Companies |๐ŸŽ“ 2000+ Students Placed

๐Ÿ”— ๐—ฅ๐—ฒ๐—ด๐—ถ๐˜€๐˜๐—ฒ๐—ฟ ๐—ก๐—ผ๐˜„ ๐Ÿ‘‡ :-

https://pdlink.in/47pezFz

๐Ÿ“ฒ Save & Share with Friends Preparing for Data Science & AI Jobs!
โค2
๐—œ๐—•๐—  ๐—™๐—ฅ๐—˜๐—˜ ๐—ง๐—˜๐—–๐—› ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! ๐ŸŽ“

Explore IBM Cognitive Class and build in-demand tech skills without spending money on course fees!

๐Ÿ“š ๐—ง๐—ผ๐—ฝ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐˜๐—ผ ๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ฒ:-

๐Ÿ’ซ Artificial Intelligence & Machine Learning
๐Ÿ”ฅPython for Data Science
๐Ÿ“Š Data Science Fundamentals
โ˜๏ธ Cloud Computing & Big Data

๐Ÿ”— ๐—ฆ๐˜๐—ฎ๐—ฟ๐˜ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด ๐—›๐—ฒ๐—ฟ๐—ฒ ๐Ÿ‘‡

https://pdlink.in/4zGswuX

๐Ÿ“ฒ Save & Share with friends preparing for tech careers! ๐Ÿ”ฅ
โค2
๐Ÿ“ฆ Common Array Interview Questions with Answers

After understanding the fundamentals of Arrays, let's look at the questions frequently asked in coding and technical interviews.

๐Ÿ”น 1. What is an Array?

Answer:

An array is a data structure used to store multiple elements in an ordered sequence.

Each element can generally be accessed using an index.

Example:

arr = [10, 20, 30, 40]

print(arr[2])


Output:

30


The index of "30" is "2".

The main advantage of an array is efficient index-based access.

๐Ÿ”น 2. What is the time complexity of accessing an array element?

Answer:

Accessing an element by its index is typically:

O(1)

Example:

arr = [10, 20, 30, 40, 50]

print(arr[3])


The system can directly access the element at index "3" rather than searching through all previous elements.

This is one of the biggest advantages of arrays.

๐Ÿ”น 3. What is the difference between an Array and a Linked List?

Answer:

An array stores elements in a contiguous structure in traditional array implementations, while a linked list stores elements as separate nodes connected using references/pointers.

Arrays provide fast index-based access:

arr[i] โ†’ O(1)

Linked lists generally require traversal to reach a particular position:

Access โ†’ O(n)

However, linked lists can be advantageous when inserting or deleting nodes at a known position because elements do not need to be shifted like they may in an array.

The choice depends on the problem.

๐Ÿ”น 4. How do you find the largest element in an array?

Answer:

Traverse the array while maintaining the largest value found so far.

Example:

arr = [10, 45, 23, 67, 12]

largest = arr[0]

for num in arr:
if num > largest:
largest = num

print(largest)


Output:

67


Time complexity:

O(n)

Space complexity:

O(1)

๐Ÿ”น 5. How do you find the second-largest element?

Answer:

We can maintain two variables:

largest

second_largest

Example:

arr = [10, 45, 23, 67, 12]

largest = float('-inf')
second_largest = float('-inf')

for num in arr:
if num > largest:
second_largest = largest
largest = num

elif num > second_largest and num != largest:
second_largest = num

print(second_largest)


Output:

45


This can be solved in:

Time: O(n)

Space: O(1)

An important interview follow-up is:

"What if all elements are equal?"

A good solution should explicitly handle the case where a distinct second-largest element does not exist.

๐Ÿ”น 6. How do you reverse an array?

Answer:

One approach is to use two pointers.

Example:

arr = [1, 2, 3, 4, 5]

left = 0
right = len(arr) - 1

while left < right:
arr[left], arr[right] = arr[right], arr[left]

left += 1
right -= 1

print(arr)


Output:

[5, 4, 3, 2, 1]


Time complexity:

O(n)

Space complexity:

O(1)

This is an example of an in-place algorithm because we modify the original array instead of creating another array.

๐Ÿ”น 7. How do you find duplicate elements in an array?

Answer:

A HashSet can be used to keep track of elements already encountered.

Example:

arr = [1, 2, 3, 2, 4, 1]

seen = set()
duplicates = set()

for num in arr:
if num in seen:
duplicates.add(num)
else:
seen.add(num)

print(duplicates)


Output:

{1, 2}
โค6๐Ÿ”ฅ1
Average time complexity:

O(n)

Additional space:

O(n)

This is usually faster than comparing every pair, which can take O(nยฒ).

๐Ÿ”น 8. What is the Two Sum problem?

Answer:

You are given an array and a target value. Find two elements whose sum equals the target.

Example:

Array: [2, 7, 11, 15]

Target: 9

The answer is:

2 + 7 = 9

A HashMap can solve this efficiently.

arr = [2, 7, 11, 15]
target = 9

seen = {}

for i, num in enumerate(arr):
complement = target - num

if complement in seen:
print(seen[complement], i)
break

seen[num] = i


Output:

0 1


Average time complexity:

O(n)

Space complexity:

O(n)

This is one of the most important patterns to recognize in array interviews.

๐Ÿ”น 9. How do you move all zeroes to the end?

Example:

Input:

[0, 1, 0, 3, 12]

Output:

[1, 3, 12, 0, 0]

A Two Pointer approach can solve this in-place.

arr = [0, 1, 0, 3, 12]

position = 0

for i in range(len(arr)):
if arr[i] != 0:
arr[position], arr[i] = arr[i], arr[position]
position += 1

print(arr)


Output:

[1, 3, 12, 0, 0]


Time complexity:

O(n)

Space complexity:

O(1)

๐Ÿ”น 10. How do you find the missing number?

Suppose the array contains numbers from "0" to "n", but one number is missing.

Example:

[3, 0, 1]

The missing number is:

2

One efficient approach uses the expected sum:

arr = [3, 0, 1]

n = len(arr)

expected_sum = n * (n + 1) // 2
actual_sum = sum(arr)

missing = expected_sum - actual_sum

print(missing)


Output:

2


Time complexity:

O(n)

Space complexity:

O(1)

๐Ÿ”น 11. What is the difference between Linear Search and Binary Search?

Answer:

Linear Search checks elements one by one.

Time: O(n)

It can work on unsorted data.

Binary Search repeatedly divides the search space approximately in half.

Time: O(log n)

It requires suitable sorted data.

For example:

Linear Search:

10 โ†’ 20 โ†’ 30 โ†’ 40 โ†’ 50

Binary Search:

30

/ \

10 40...

The key interview point is not simply memorizing the complexities. You should understand when Binary Search can actually be applied.

๐Ÿ”น 12. What is an in-place algorithm?

Answer:

An in-place algorithm modifies the input data structure while using only a small amount of additional memory.

For example, reversing an array using two pointers:

arr = [1, 2, 3, 4]

left = 0
right = len(arr) - 1

while left < right:
arr[left], arr[right] = arr[right], arr[left]
left += 1
right -= 1


No second array is created.

Therefore, the extra space used is:

O(1)

๐Ÿ”น 13. What is the Maximum Subarray problem?

Answer:

You are given an array of integers and need to find the contiguous subarray with the maximum sum.

Example:

[-2, 1, -3, 4, -1, 2, 1, -5, 4]

The maximum-sum contiguous subarray is:

[4, -1, 2, 1]

Its sum is:

6

A famous solution uses Kadane's Algorithm.

arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]

current = arr[0]
maximum = arr[0]

for i in range(1, len(arr)):
current = max(arr[i], current + arr[i])
maximum = max(maximum, current)

print(maximum)


Output:

6
โค1๐Ÿ˜1