Menu

Navigation

HomeAll CompaniesPrevious Year QuestionsTNP / PlacementsBEU ResultDocumentation

Companies

InfosysTCSWiproAccentureCognizantCapgemini
R's PlacePrep|
CompaniesPYQDocs

Company

Infosys

Content

2025 IRT2024 IRTAptitudeCoding

View Options

Display Mode

Sections

Quantitative Aptitude20
Logical Reasoning20
Verbal Ability15
Pseudo Code15
Coding Problems12

Export

PDF

Word

Last updated: Feb 11, 2026

Infosys

2025 IRT

Display Mode

Jump to Section

Quantitative Aptitude20
Logical Reasoning20
Verbal Ability15
Pseudo Code15
Coding Problems12

Other Content

2025 IRT2024 IRTAptitudeCoding

Export

PDF

Word

Home/Companies/Infosys/2025-irt
Back to Infosys

Infosys 2025-irt

5 sections, 82 questions

Quantitative Aptitude

20 questions
Question 1

Percentage Problem

Problem

The price of a product increased by 20%. By what percentage should consumption be reduced to keep expenditure same?

Solution

Let original price = ₹100, consumption = 100 units
New price = ₹120
Original expenditure = ₹10,000
New consumption = 10,000 / 120 = 83.33 units
Reduction = (100 - 83.33) / 100 × 100 = 16.67%

Question 2

Mixture Problem

Problem

A mixture contains milk and water in ratio 3:2. If 10 liters of water is added, ratio becomes 2:3. Find initial quantity of mixture.

Solution

Let initial: Milk = 3x, Water = 2x
After adding 10L water: Milk = 3x, Water = 2x + 10
3x / (2x + 10) = 2/3
9x = 4x + 20
5x = 20
x = 4
Initial quantity = 3x + 2x = 5x = 20 liters

Question 3

Profit & Loss - Successive Discounts

Problem

A shopkeeper gives two successive discounts of 10% and 20% on an item. What is the effective discount percentage?

Solution

Let MP = ₹100
After first discount: 100 - 10% = ₹90
After second discount: 90 - 20% = ₹72
Effective discount = (100 - 72) / 100 × 100 = 28%

Question 4

Time & Work - Efficiency

Problem

A is twice as efficient as B. Together they complete a work in 12 days. In how many days will A alone complete it?

Solution

Let B's efficiency = 1 unit/day
A's efficiency = 2 units/day
Together: 1 + 2 = 3 units/day
Total work = 3 × 12 = 36 units
A alone: 36 / 2 = 18 days

Question 5

Simple Interest - Rate Calculation

Problem

A sum of ₹8,000 amounts to ₹9,600 in 4 years at simple interest. Find the rate of interest per annum.

Solution

Principal = ₹8,000, Amount = ₹9,600
Interest = 9,600 - 8,000 = ₹1,600
SI = P × R × T / 100
1,600 = 8,000 × R × 4 / 100
R = (1,600 × 100) / (8,000 × 4) = 5%

Question 6

Compound Interest - Half Yearly

Problem

Find compound interest on ₹5,000 for 1 year at 10% per annum, compounded half-yearly.

Solution

Rate per half year = 10/2 = 5%
Number of periods = 2
Amount = 5000(1 + 5/100)² = 5000 × 1.05² = 5000 × 1.1025 = ₹5,512.50
CI = 5,512.50 - 5,000 = ₹512.50

Question 7

Speed & Distance - Relative Speed

Problem

Two trains of lengths 100m and 150m are running in the same direction at speeds of 50 km/hr and 40 km/hr respectively. Find the time taken by faster train to overtake the slower train.

Solution

Relative speed = 50 - 40 = 10 km/hr = 10 × 5/18 = 25/9 m/s
Distance to cover = 100 + 150 = 250m
Time = 250 / (25/9) = 250 × 9/25 = 90 seconds

Question 8

Speed & Distance - Average Speed

Problem

A person travels first half of distance at 40 km/hr and second half at 60 km/hr. Find average speed.

Solution

Let total distance = 2D
Time for first half = D/40
Time for second half = D/60
Total time = D/40 + D/60 = D(3+2)/120 = 5D/120 = D/24
Average speed = 2D / (D/24) = 48 km/hr

Question 9

Permutations - Arrangements

Problem

In how many ways can 5 people be arranged in a row if two particular people must sit together?

Solution

Treat the two people as one unit: 4 units to arrange = 4! ways
The two people can be arranged among themselves in 2! ways
Total = 4! × 2! = 24 × 2 = 48 ways

Question 10

Combinations - Selection

Problem

In how many ways can 3 students be selected from a group of 8 students?

Solution

Number of ways = C(8,3) = 8! / (3! × 5!) = (8 × 7 × 6) / (3 × 2 × 1) = 56

Question 11

Pipes & Cisterns - Multiple Pipes

Problem

Three pipes A, B, C can fill a tank in 12, 15, and 20 hours respectively. If all three are opened together, how long will it take to fill the tank?

Solution

A's rate = 1/12 per hour
B's rate = 1/15 per hour
C's rate = 1/20 per hour
Combined rate = 1/12 + 1/15 + 1/20 = (5+4+3)/60 = 12/60 = 1/5 per hour
Time = 1 / (1/5) = 5 hours

Question 12

Probability - Cards

Problem

Two cards are drawn from a pack of 52 cards. What is the probability that both are aces?

Solution

Probability = (4/52) × (3/51) = (1/13) × (1/17) = 1/221

Question 13

Ratio & Proportion - Three Quantities

Problem

If A:B = 2:3 and B:C = 4:5, find A:B:C.

Solution

A:B = 2:3 = 8:12 (multiply by 4)
B:C = 4:5 = 12:15 (multiply by 3)
A:B:C = 8:12:15

Question 14

Percentage - Successive Changes

Problem

A number is first increased by 25% and then decreased by 20%. Find the net percentage change.

Solution

Let number = 100
After 25% increase: 100 + 25 = 125
After 20% decrease: 125 - 20% of 125 = 125 - 25 = 100
Net change = 0%

Question 15

Time & Work - Work and Wages

Problem

A can do a work in 10 days and B in 15 days. They work together for 4 days and then A leaves. If total wages is ₹3,000, find B's share.

Solution

A's 1 day work = 1/10, B's 1 day work = 1/15
Together in 1 day = 1/10 + 1/15 = 1/6
Work done in 4 days = 4/6 = 2/3
Remaining work = 1/3
B completes remaining work alone
Ratio of work: A = 4/10 = 2/5, B = 4/15 + 1/3 = 4/15 + 5/15 = 9/15 = 3/5
B's share = (3/5) / (2/5 + 3/5) × 3000 = (3/5) / 1 × 3000 = ₹1,800

Question 16

Data Interpretation - Table

Problem

If Product A sold 25% more than Product B, and Product B sold 40,000 units, find Product A's sales.

Solution

Product B = 40,000
Product A = 40,000 + 25% of 40,000 = 40,000 + 10,000 = 50,000

Question 17

Ages - Ratio Problem

Problem

The ratio of present ages of father and son is 7:3. After 10 years, the ratio becomes 2:1. Find the present age of father.

Solution

Let present ages: Father = 7x, Son = 3x
After 10 years: (7x + 10)/(3x + 10) = 2/1
7x + 10 = 2(3x + 10)
7x + 10 = 6x + 20
7x - 6x = 20 - 10
x = 10
Father's present age = 7 × 10 = 70 years

Question 18

Partnership - Investment Periods

Problem

A invests ₹5,000 for 6 months, B invests ₹6,000 for 8 months. If profit is ₹4,200, find A's share.

Solution

A's investment × time = 5,000 × 6 = 30,000
B's investment × time = 6,000 × 8 = 48,000
Ratio = 30,000 : 48,000 = 5 : 8
A's share = 5/(5+8) × 4,200 = 5/13 × 4,200 = ₹1,615.38

Question 19

Boats & Streams - Upstream/Downstream

Problem

A boat takes 3 hours to go 12 km upstream and 2 hours to go 12 km downstream. Find the speed of the boat in still water.

Solution

Upstream speed = 12/3 = 4 km/hr
Downstream speed = 12/2 = 6 km/hr
Speed in still water = (4 + 6)/2 = 5 km/hr

Question 20

Number System - Divisibility

Problem

Find the smallest number that must be added to 1056 to make it divisible by 23.

Solution

1056 ÷ 23 = 45 remainder 21
Number to add = 23 - 21 = 2

Logical Reasoning

20 questions
Question 1

Number Series - Square Pattern

Problem

Find next number: 1, 4, 9, 16, 25, ?

Solution

Pattern: n² where n = 1, 2, 3, 4, 5…
1²=1, 2²=4, 3²=9, 4²=16, 5²=25
Next: 6² = 36

Question 2

Number Series - Prime Pattern

Problem

Find next number: 2, 3, 5, 7, 11, ?

Solution

Pattern: Prime numbers in sequence
2, 3, 5, 7, 11, 13…
Next: 13

Question 3

Number Series - Fibonacci Variant

Problem

Find next number: 1, 1, 2, 3, 5, 8, ?

Solution

Pattern: Fibonacci sequence (each number is sum of previous two)
1, 1, 2, 3, 5, 8, 13…
Next: 13

Question 4

Letter Series - Skip Pattern

Problem

Find next letter: B, E, H, K, ?

Solution

Pattern: B(+3)→E(+3)→H(+3)→K(+3)→N
Next letter = N

Question 5

Coding-Decoding - Reverse Pattern

Problem

If "INFOSYS" is coded as "SYFOSNI", how is "SYSTEM" coded?

Solution

Pattern: Letters are reversed
INFOSYS → SYFOSNI (reversed)
SYSTEM → METSYS (reversed)

Question 6

Coding-Decoding - Position Sum

Problem

If "CAT" is coded as "3120" (C=3, A=1, T=20), how is "DOG" coded?

Solution

D = 4, O = 15, G = 7
Code = 4157

Question 7

Syllogism - Three Statements

Problem

Statements:

  1. Some books are novels
  2. All novels are stories
  3. No story is a poem

Conclusions:

  • I) Some books are stories
  • II) No novel is a poem
  • III) Some stories are books

Solution

From 1 and 2: Some books are stories (I follows)
From 2 and 3: No novel is a poem (II follows)
From I: Some stories are books (III follows)

Question 8

Blood Relations - Complex

Problem

Pointing to a photograph, a man said, "She is the daughter of my grandfather's only son." How is the man related to the person in the photograph?

Solution

Grandfather's only son = man's father
Daughter of man's father = man's sister
So the person is the man's sister

Question 9

Direction Sense - Multiple Turns

Problem

A person walks 10m north, then 5m east, then 10m south, then 5m west. Where is he from starting point?

Solution

Net north = 10 - 10 = 0
Net east = 5 - 5 = 0
He is at the starting point

Question 10

Seating Arrangement - Circular with Conditions

Problem

Six friends A, B, C, D, E, F sit around a circular table. A sits opposite D. B sits between A and C. E is not adjacent to A. Who sits opposite E?

Solution

In circular arrangement with 6 people, opposite pairs: (A,D), (B,E), (C,F)
Since A is opposite D, and B is between A and C, and E is not adjacent to A
E must be opposite B

Question 11

Ordering & Ranking - From Both Ends

Problem

In a queue, Ravi is 15th from front and 20th from back. How many people are in the queue?

Solution

Total = Position from front + Position from back - 1
Total = 15 + 20 - 1 = 34

Question 12

Cube Problem - Three Colors

Problem

A cube is painted red on two opposite faces, blue on two adjacent faces, and left unpainted on remaining faces. It is cut into 64 smaller cubes. How many cubes have exactly one painted face?

Solution

4×4×4 cube = 64 cubes
Cubes with exactly 1 painted face are on face centers (excluding edges and corners)
For each painted face: 2×2 = 4 center cubes
4 painted faces × 4 center cubes = 16 cubes

Question 13

Statement & Assumptions

Problem

Statement: "Use our product for better results."

Assumptions:

  • I) People want better results
  • II) The product gives better results

Solution

Both assumptions are implicit in the statement

Question 14

Data Sufficiency - Two Statements

Problem

What is the value of x + y?

Statement 1: x = 5
Statement 2: y = 10

Solution

From statement 1: x = 5, but y unknown
From statement 2: y = 10, but x unknown
Combining both: x + y = 5 + 10 = 15

Question 15

Logical Deduction - Conditional

Problem

If all roses are flowers, and some flowers are red, which must be true?

a) All roses are red
b) Some roses are red
c) Some red things are flowers
d) None of the above

Solution

From "all roses are flowers" and "some flowers are red", we cannot conclude about roses being red. But "some red things are flowers" must be true.

Question 16

Pattern Recognition - Alternating

Problem

Find next number: 2, 5, 10, 17, 26, ?

Solution

Pattern: Differences are 3, 5, 7, 9 (odd numbers)
Next difference = 11
Next number = 26 + 11 = 37

Question 17

Seating Arrangement - Linear with Conditions

Problem

Five people A, B, C, D, E sit in a row. A is not at either end. B sits next to A. C sits at one end. D sits between C and E. Who sits in the middle?

Solution

C is at one end. D is between C and E, so: C-D-E or E-D-C
A is not at end, B is next to A
If C-D-E, then A-B must be before: A-B-C-D-E (A at end, invalid)
So: C-D-E-B-A or C-D-E-A-B
Middle position: E

Question 18

Blood Relations - Generation Skip

Problem

A is the father of B. C is the son of B. D is the brother of A. How is D related to C?

Solution

A is father of B, so B is child of A
C is son of B, so C is grandson of A
D is brother of A, so D is uncle of B
Therefore, D is great-uncle of C

Question 19

Direction Sense - Clockwise

Problem

A person faces north. He turns 90° clockwise, then 180° clockwise, then 270° clockwise. In which direction is he facing now?

Solution

Starting: North
After 90° clockwise: East
After 180° clockwise: West
After 270° clockwise: North (270° clockwise = 90° anticlockwise from West)

Question 20

Number Series - Multiplication Pattern

Problem

Find next number: 3, 6, 12, 24, 48, ?

Solution

Pattern: Each number = previous × 2
3×2=6, 6×2=12, 12×2=24, 24×2=48
Next: 48×2 = 96

Verbal Ability

15 questions
Question 1

Reading Comprehension - Inference

Problem

Passage: "Cloud computing has transformed how businesses operate. Companies can now access computing resources on-demand without maintaining physical infrastructure. This has led to significant cost savings and increased flexibility."

Question: What is the main advantage of cloud computing mentioned?

Question 2

Grammar - Parallelism

Problem

Choose the correct sentence:

a) She likes reading, writing, and to dance
b) She likes reading, writing, and dancing
c) She likes to read, writing, and dancing

Solution

Parallel structure requires same form: all gerunds or all infinitives. Option b maintains parallelism with all gerunds.

Question 3

Grammar - Conditional Sentences

Problem

Choose the correct form: "If I _____ rich, I would travel the world."

a) am
b) was
c) were
d) will be

Solution

Second conditional uses "were" for all subjects (subjunctive mood).

Question 4

Vocabulary - Synonyms

Problem

Find the synonym of "MAGNIFICENT":

a) Ordinary
b) Splendid
c) Small
d) Ugly

Solution

Magnificent means impressively beautiful or grand, so "Splendid" is the synonym.

Question 5

Vocabulary - Antonyms

Problem

Find the antonym of "BRILLIANT":

a) Bright
b) Dull
c) Shining
d) Smart

Solution

Brilliant means very bright or intelligent, so "Dull" is the antonym.

Question 6

Sentence Correction - Articles

Problem

Choose the correct sentence:

a) He is a honest man
b) He is an honest man
c) He is the honest man

Solution

"Honest" starts with a vowel sound, so "an" is used.

Question 7

Para Jumbles - Logical Flow

Problem

Arrange the sentences:

  1. Therefore, regular exercise is essential
  2. Physical activity improves mental health
  3. Studies show that exercise reduces stress
  4. It also enhances cognitive function

Solution

Logical order: 3 (evidence) → 2 (benefit) → 4 (additional benefit) → 1 (conclusion)

Question 8

Error Spotting - Pronoun Agreement

Problem

Find the error: "Each of the students have completed their assignment."

Solution

"Each" is singular, so "has" should be used instead of "have", and "his or her" instead of "their".

Question 9

Fill in the Blanks - Prepositions

Problem

"She is allergic _____ peanuts."

a) to
b) from
c) with
d) by

Solution

"Allergic to" is the correct prepositional phrase.

Question 10

Idioms & Phrases

Problem

What does "Hit the nail on the head" mean?

a) To make a mistake
b) To be exactly right
c) To cause trouble
d) To work hard

Solution

"Hit the nail on the head" means to be exactly right or accurate.

Question 11

Reading Comprehension - Main Idea

Problem

Passage: "Renewable energy sources like solar and wind power are becoming increasingly cost-effective. Many countries are investing heavily in these technologies to reduce carbon emissions and combat climate change."

Question: What is the main topic of the passage?

Question 12

Sentence Completion - Conjunctions

Problem

"She studied hard _____ she could pass the exam."

a) so that
b) because
c) although
d) unless

Solution

"So that" indicates purpose, which fits the context.

Question 13

Word Usage - Commonly Confused

Problem

Choose the correct word: "The _____ of the meeting was productive."

a) affect
b) effect
c) impact
d) result

Solution

"Effect" (noun) means result, while "affect" (verb) means to influence. Here we need a noun.

Question 14

Active/Passive Voice - Complex

Problem

Convert to passive: "They are building a new bridge."

Solution

Passive voice: "A new bridge is being built by them."

Question 15

Sentence Improvement

Problem

Choose the improved version: "The data shows that the company's profits have increased."

a) The data show that the company's profits have increased
b) The data shows that the company's profit have increased
c) The datas show that the company's profits have increased

Solution

"Data" can be singular or plural, but "shows" (singular) is commonly accepted. Option a uses plural verb which is also correct.

Pseudo Code

15 questions
Question 1

C Output - Post and Pre Increment

Problem

What is the output?

int main() {
    int a = 5, b = 10;
    printf("%d %d", a++, ++b);
    printf(" %d %d", a, b);
    return 0;
}

Solution

  • a++ uses 5, then a becomes 6
  • ++b makes b = 11, uses value 11
  • First printf: 5 11
  • Second printf: 6 11
Question 2

Loop with Break

Problem

What is the output?

int main() {
    int i;
    for(i=1; i<=10; i++) {
        if(i == 5) break;
        printf("%d ", i);
    }
    return 0;
}

Solution

Loop executes: i=1 prints 1, i=2 prints 2, i=3 prints 3, i=4 prints 4, i=5 breaks

Question 3

Array and Pointer

Problem

What is the output?

int main() {
    int arr[] = {10, 20, 30, 40};
    int *p = arr;
    printf("%d %d", *p, *(p+3));
    return 0;
}

Solution

  • p points to arr[0] = 10
  • *p = 10
  • *(p+3) = arr[3] = 40
Question 4

Recursion - Sum

Problem

What is the output?

int sum(int n) {
    if(n == 0) return 0;
    return n + sum(n-1);
}

printf("%d", sum(5));

Solution

  • sum(5) = 5 + sum(4)
  • sum(4) = 4 + sum(3)
  • sum(3) = 3 + sum(2)
  • sum(2) = 2 + sum(1)
  • sum(1) = 1 + sum(0)
  • sum(0) = 0

Working back:

  • sum(1) = 1 + 0 = 1
  • sum(2) = 2 + 1 = 3
  • sum(3) = 3 + 3 = 6
  • sum(4) = 4 + 6 = 10
  • sum(5) = 5 + 10 = 15
Question 5

String Length

Problem

What is the output?

int main() {
    char str[] = "INFOSYS";
    int len = 0;
    while(str[len] != '\0') len++;
    printf("%d", len);
    return 0;
}

Solution

"INFOSYS" has 7 characters, len = 7

Question 6

Pointer Arithmetic - Advanced

Problem

What is the output?

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    int *p = &arr[2];
    printf("%d %d", p[-1], p[1]);
    return 0;
}

Solution

  • p points to arr[2] = 3
  • p[-1] = arr[1] = 2
  • p[1] = arr[3] = 4
Question 7

Nested Loops - Pattern

Problem

What is the output?

int main() {
    int i, j;
    for(i=1; i<=3; i++) {
        for(j=1; j<=i; j++) {
            printf("%d", j);
        }
        printf("\n");
    }
    return 0;
}

Solution

  • i=1: j=1, prints 1, newline
  • i=2: j=1,2, prints 12, newline
  • i=3: j=1,2,3, prints 123, newline
Question 8

Java Output - String

Problem

What is the output?

public class Test {
    public static void main(String[] args) {
        String s1 = "Hello";
        String s2 = new String("Hello");
        System.out.println(s1 == s2);
        System.out.println(s1.equals(s2));
    }
}

Solution

  • s1 == s2 compares references (false, different objects)
  • s1.equals(s2) compares content (true, same string)
Question 9

Python Output - List

Problem

What is the output?

def func(lst):
    if len(lst) == 0:
        return 0
    return lst[0] + func(lst[1:])

print(func([1, 2, 3, 4]))

Solution

  • func([1,2,3,4]) = 1 + func([2,3,4])
  • func([2,3,4]) = 2 + func([3,4])
  • func([3,4]) = 3 + func([4])
  • func([4]) = 4 + func([])
  • func([]) = 0

Working back:

  • func([4]) = 4 + 0 = 4
  • func([3,4]) = 3 + 4 = 7
  • func([2,3,4]) = 2 + 7 = 9
  • func([1,2,3,4]) = 1 + 9 = 10
Question 10

Conditional - Ternary

Problem

What is the output?

int main() {
    int x = 15, y = 10;
    int z = (x > y) ? x : y;
    printf("%d", z);
    return 0;
}

Solution

  • x > y is true (15 > 10)
  • So z = x = 15
Question 11

Array Traversal

Problem

What is the output?

int main() {
    int arr[5] = {1, 2, 3, 4, 5};
    int sum = 0;
    for(int i=0; i<5; i++) {
        if(arr[i] % 2 == 0) sum += arr[i];
    }
    printf("%d", sum);
    return 0;
}

Solution

Even numbers: 2, 4
Sum = 2 + 4 = 6

Question 12

While Loop - Count

Problem

What is the output?

int main() {
    int count = 0, num = 1234;
    while(num > 0) {
        count++;
        num /= 10;
    }
    printf("%d", count);
    return 0;
}

Solution

  • num=1234, count=1, num=123
  • num=123, count=2, num=12
  • num=12, count=3, num=1
  • num=1, count=4, num=0
  • count = 4
Question 13

Function - Parameter Passing

Problem

What is the output?

void change(int x) {
    x = 20;
}

int main() {
    int a = 10;
    change(a);
    printf("%d", a);
    return 0;
}

Solution

Parameters are passed by value in C, so change() doesn't affect a. a remains 10.

Question 14

String Copy

Problem

What is the output?

int main() {
    char src[] = "Hello";
    char dest[10];
    int i = 0;
    while(src[i] != '\0') {
        dest[i] = src[i];
        i++;
    }
    dest[i] = '\0';
    printf("%s", dest);
    return 0;
}

Solution

Copies "Hello" to dest, prints "Hello"

Question 15

Modulo and Division

Problem

What is the output?

int main() {
    int x = 25;
    printf("%d %d", x / 4, x % 4);
    return 0;
}

Solution

  • 25 / 4 = 6 (integer division)
  • 25 % 4 = 1 (remainder)

Coding Problems

12 questions
Question 1

Palindrome Check

Problem

Check if string is palindrome (case-insensitive).

Solution



Code

Python
def is_palindrome(s):
    s = s.lower()
    left, right = 0, len(s) - 1
    while left < right:
        if s[left] != s[right]:
            return False
        left += 1
        right -= 1
    return True
C
#include <string.h>
#include <ctype.h>

int is_palindrome(char str[]) {
    int left = 0, right = strlen(str) - 1;
    while (left < right) {
        if (tolower(str[left]) != tolower(str[right]))
            return 0;
        left++;
        right--;
    }
    return 1;
}
Time: O(n)Space: O(1)
Question 2

Find Maximum Element

Problem

Find the maximum element in an array.

Solution



Code

C
int findMax(int arr[], int n) {
    int max = arr[0];
    for (int i = 1; i < n; i++) {
        if (arr[i] > max)
            max = arr[i];
    }
    return max;
}
Python
def find_max(arr):
    max_val = arr[0]
    for num in arr[1:]:
        if num > max_val:
            max_val = num
    return max_val
Time: O(n)Space: O(1)
Question 3

Count Vowels

Problem

Count the number of vowels in a string.

Solution



Code

C
#include <ctype.h>

int countVowels(char str[]) {
    int count = 0;
    for (int i = 0; str[i] != '\0'; i++) {
        char c = tolower(str[i]);
        if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
            count++;
    }
    return count;
}
Python
def count_vowels(s):
    vowels = 'aeiouAEIOU'
    return sum(1 for char in s if char in vowels)
Time: O(n)Space: O(1)
Question 4

Sum of Array Elements

Problem

Find sum of all elements in an array.

Solution



Code

C
int arraySum(int arr[], int n) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += arr[i];
    }
    return sum;
}
Python
def array_sum(arr):
    total = 0
    for num in arr:
        total += num
    return total
Time: O(n)Space: O(1)
Question 5

Linear Search

Problem

Search for an element in an array.

Solution



Code

C
int linearSearch(int arr[], int n, int key) {
    for (int i = 0; i < n; i++) {
        if (arr[i] == key)
            return i;
    }
    return -1;
}
Python
def linear_search(arr, key):
    for i, num in enumerate(arr):
        if num == key:
            return i
    return -1
Time: O(n)Space: O(1)
Question 6

Reverse String

Problem

Reverse a string without using built-in functions.

Solution



Code

C
#include <string.h>

void reverseString(char str[]) {
    int len = strlen(str);
    int start = 0, end = len - 1;
    while (start < end) {
        char temp = str[start];
        str[start] = str[end];
        str[end] = temp;
        start++;
        end--;
    }
}
Python
def reverse_string(s):
    chars = list(s)
    left, right = 0, len(chars) - 1
    while left < right:
        chars[left], chars[right] = chars[right], chars[left]
        left += 1
        right -= 1
    return ''.join(chars)
Time: O(n)Space: O(1)
Question 7

Check Prime Number

Problem

Check if a number is prime.

Solution



Code

C
#include <math.h>

int isPrime(int n) {
    if (n <= 1) return 0;
    if (n <= 3) return 1;
    if (n % 2 == 0 || n % 3 == 0) return 0;
    for (int i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0)
            return 0;
    }
    return 1;
}
Python
def is_prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True
Time: O(√n)Space: O(1)
Question 8

Find Missing Number

Problem

Find missing number in array containing numbers from 1 to n (one missing).

Solution



Code

C
int findMissing(int arr[], int n) {
    int total = (n + 1) * (n + 2) / 2;
    for (int i = 0; i < n; i++)
        total -= arr[i];
    return total;
}
Python
def find_missing(arr, n):
    expected_sum = (n + 1) * (n + 2) // 2
    actual_sum = sum(arr)
    return expected_sum - actual_sum
Time: O(n)Space: O(1)
Question 9

Remove Duplicates from Sorted Array

Problem

Remove duplicates from sorted array and return new length.

Solution



Code

C
int removeDuplicates(int arr[], int n) {
    if (n == 0) return 0;
    int j = 0;
    for (int i = 1; i < n; i++) {
        if (arr[i] != arr[j]) {
            j++;
            arr[j] = arr[i];
        }
    }
    return j + 1;
}
Python
def remove_duplicates(arr):
    if not arr:
        return 0
    j = 0
    for i in range(1, len(arr)):
        if arr[i] != arr[j]:
            j += 1
            arr[j] = arr[i]
    return j + 1
Time: O(n)Space: O(1)
Question 10

Check Anagram

Problem

Check if two strings are anagrams.

Solution



Code

C
#include <string.h>
#include <ctype.h>

int areAnagrams(char str1[], char str2[]) {
    int count[256] = {0};
    int len1 = strlen(str1), len2 = strlen(str2);
    if (len1 != len2) return 0;
    
    for (int i = 0; i < len1; i++) {
        count[tolower(str1[i])]++;
        count[tolower(str2[i])]--;
    }
    
    for (int i = 0; i < 256; i++) {
        if (count[i] != 0) return 0;
    }
    return 1;
}
Python
def are_anagrams(s1, s2):
    s1 = s1.lower()
    s2 = s2.lower()
    if len(s1) != len(s2):
        return False
    return sorted(s1) == sorted(s2)
Time: O(n) or O(n log n) for sortingSpace: O(1) or O(n)
Question 11

Find Second Smallest

Problem

Find the second smallest element in an array.

Solution



Code

C
#include <limits.h>

int secondSmallest(int arr[], int n) {
    int first = INT_MAX, second = INT_MAX;
    for (int i = 0; i < n; i++) {
        if (arr[i] < first) {
            second = first;
            first = arr[i];
        } else if (arr[i] < second && arr[i] != first) {
            second = arr[i];
        }
    }
    return second;
}
Python
def second_smallest(arr):
    first = second = float('inf')
    for num in arr:
        if num < first:
            second = first
            first = num
        elif num < second and num != first:
            second = num
    return second
Time: O(n)Space: O(1)
Question 12

Count Character Frequency

Problem

Count frequency of each character in a string.

Solution



Code

C
#include <string.h>
#include <stdio.h>

void countFrequency(char str[]) {
    int count[256] = {0};
    int len = strlen(str);
    
    for (int i = 0; i < len; i++) {
        count[(int)str[i]]++;
    }
    
    for (int i = 0; i < 256; i++) {
        if (count[i] > 0) {
            printf("%c: %d\n", i, count[i]);
        }
    }
}
Python
def count_frequency(s):
    freq = {}
    for char in s:
        freq[char] = freq.get(char, 0) + 1
    return freq
Time: O(n)Space: O(k) where k is unique characters

Last updated: 2026-02-11

Radhika's PlacePrep built by Rohan Sharma