Wipro Previous Coding Questions
π₯ Wipro Previous Coding Questions with Java & Python Solutions
Welcome to this carefully curated post featuring Wipro Previous Coding Questions asked in real campus placements and technical assessments.
Each problem includes:
β
A clear and beginner-friendly problem statement
β
Java and Python code solutions
β
Sample input and output formats
β
Easy-to-understand explanation of the logic
Whether you’re preparing for Wiproβs Elite NTH, Turbo hiring, or just practicing for coding rounds β this guide will help you strengthen your logic and problem-solving skills.
Letβs get started and crack that Wipro coding round! π»π
β Problem 1: Lowest Number in the List
π Problem Statement
Given a list of integers, find the lowest (minimum) number in the list.
π’ Input
- First line: An integer n representing the number of elements
- Second line: n space-separated integers
π§Ύ Output
- The smallest integer in the list
β Example
Input:
5
4 9 1 7 3
Output:
1
π£Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int min = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { int val = sc.nextInt(); if (val < min) min = val; } System.out.println(min); } } |
1 2 3 |
n = int(input()) arr = list(map(int, input().split())) print(min(arr)) |
π Explanation
Loop through all numbers and track the smallest value found.
β Problem 2: Find Missing Numbers Between Lists
π Problem Statement
You are given three lists: A, B, and C.
- B contains all the elements of A except one.
- C contains all the elements of B except one.
Your task is to determine which two numbers are missingβ
- First, find the number that is in A but not in B.
- Second, find the number that is in B but not in C.
π’ Input
- An integer N
- A list of N integers (A)
- A list of N-1 integers (B)
- A list of N-2 integers (C)
π§Ύ Output
- Print the two missing numbers on separate lines.
β Example
Input:
5
4 5 3 2 1
5 3 2 1
3 1 2
Output:
4
5
π£Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long sumA = 0, sumB = 0, sumC = 0; for (int i = 0; i < n; i++) sumA += sc.nextInt(); for (int i = 0; i < n - 1; i++) sumB += sc.nextInt(); for (int i = 0; i < n - 2; i++) sumC += sc.nextInt(); System.out.println(sumA - sumB); System.out.println(sumB - sumC); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
def find_missing_numbers(): n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) missing1 = sum(A) - sum(B) missing2 = sum(B) - sum(C) print(missing1) print(missing2) # Sample Run find_missing_numbers() |
π Explanation
Subtract the partial list from the original using set operations.
β Problem 3: Add Up the Evens
π Problem Statement
Given a list of numbers, find the sum of all even numbers in the list.
π’ Input
- First line: Integer n, the number of elements
- Second line: n space-separated integers
π§Ύ Output
- Single integer representing the sum of even numbers
β Example
Input:
6 1 2 3 4 5 6
Output:
12
π£Code
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), sum = 0; for (int i = 0; i < n; i++) { int val = sc.nextInt(); if (val % 2 == 0) sum += val; } System.out.println(sum); } } |
1 2 3 4 |
n = int(input()) arr = list(map(int, input().split())) even_sum = sum(x for x in arr if x % 2 == 0) print(even_sum) |
π Explanation
Use modulo to check if a number is even and then sum it up.
β Problem 4: Clockwise Angle Between Hour Marks
π Problem Statement
Given two numbers representing hour marks on a clock (1β12), find the clockwise angle between them.
π’ Input
- Two integers between 1 and 12
π§Ύ Output
- The clockwise angle between them in degrees (each hour = 30Β°)
β Example
Input:
3 6
Output:
90
π£Code
1 2 3 4 5 6 7 8 9 10 |
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(), b = sc.nextInt(); int angle = ((b - a + 12) % 12) * 30; System.out.println(angle); } } |
1 2 3 |
a, b = map(int, input().split()) angle = (b - a) % 12 * 30 print(angle) |
π Explanation
There are 12 hour marks, and each mark is 30Β°. Calculate clockwise difference modulo 12.
β Problem 5: GCD of Two Numbers
π Problem Statement
Find the Greatest Common Divisor (GCD) of two given integers.
π’ Input
- Two space-separated integers from a single line: a b
π§Ύ Output
- A single integer representing their GCD
β Example
Input:
12 18
Output:
6
π£Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import java.util.Scanner; public class Main { static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(), b = sc.nextInt(); System.out.println(gcd(a, b)); } } |
1 2 3 4 |
import math a, b = map(int, input().split()) print(math.gcd(a, b)) |
π Explanation
We use the Euclidean algorithm. If b is 0, a is the GCD; otherwise, recurse with b and a % b.
β Problem 6: GCD of Three Numbers
π Problem Statement
Compute the GCD of three integers.
π’ Input
- Three space-separated integers: a b c
π§Ύ Output
- Single integer: GCD of all three numbers
β Example
Input:
15 30 45
Output:
15
π£Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import java.util.Scanner; public class Main { static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(); int g = gcd(a, b); System.out.println(gcd(g, c)); } } |
1 2 3 4 5 |
import math a, b, c = map(int, input().split()) g = math.gcd(a, b) print(math.gcd(g, c)) |
π Explanation
Find the GCD of first two numbers, then compute GCD of the result with the third number.
β Problem 7: Check if a Number is Prime
π Problem Statement
Determine whether a given number is a prime number.
π’ Input
- A single integer n
π§Ύ Output
- Print Prime if the number is prime, otherwise print not prime
β Example
Input:
7
Output:
Prime
π£Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import java.util.Scanner; public class Main { public static boolean isPrime(int n) { if (n <= 1) return false; for (int i = 2; i <= Math.sqrt(n); i++) if (n % i == 0) return false; return true; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); System.out.println(isPrime(n) ? "Prime" : "Not Prime"); } } |
1 2 3 4 5 6 7 8 9 10 11 12 |
import math n = int(input()) if n <= 1: print("Not Prime") else: for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: print("Not Prime") break else: print("Prime") |
π Explanation
We check for divisibility from 2 to βn. If divisible, itβs not prime.
β Problem 8: Display Distinct Elements of an Array
π Problem Statement
Print all distinct elements from the input list while preserving the order of first appearance.
π’ Input
- Space-separated integers on a single line
π§Ύ Output
- Space-separated integers with duplicates removed
β Example
Input:
1 2 2 3 4 3 5
Output:
1 2 3 4 5
π£Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] parts = sc.nextLine().split(" "); Set<Integer> seen = new HashSet<>(); for (String p : parts) { int num = Integer.parseInt(p); if (seen.add(num)) { System.out.print(num + " "); } } } } |
1 2 3 4 5 6 7 8 |
arr = list(map(int, input().split())) seen = set() res = [] for num in arr: if num not in seen: seen.add(num) res.append(num) print(*res) |
π Explanation
Use a set to track seen elements and ensure no duplicates are printed.
β Problem 9: Remove Vowels from a String
π Problem Statement
Remove all vowels (a, e, i, o, u) from the input string.
π’ Input
- A single line string
π§Ύ Output
- The string with vowels removed
β Example
Input:
ChatGPT is awesome
Output:
ChtGPT s wsm
π£Code
1 2 3 4 5 6 7 8 |
import java.util.Scanner; public class Main { public static void main(String[] args) { String input = new Scanner(System.in).nextLine(); System.out.println(input.replaceAll("(?i)[aeiou]", "")); } } |
1 2 3 |
s = input() vowels = "aeiouAEIOU" print(''.join([c for c in s if c not in vowels])) |
π Explanation
We filter out vowels using list comprehension (Python) or regex (Java).
β Problem 10: Sum of All Odd Digits in a Number
π Problem Statement
Find the sum of all odd digits in the given number.
π’ Input
- A single integer
π§Ύ Output
- Sum of all odd digits
β Example
Input:
53821
Output:
17
(5 + 3 + 1 + 7)
π£Code
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import java.util.Scanner; public class Main { public static void main(String[] args) { String n = new Scanner(System.in).nextLine(); int sum = 0; for (char ch : n.toCharArray()) { int digit = ch - '0'; if (digit % 2 != 0) sum += digit; } System.out.println(sum); } } |
1 2 3 |
n = input() odd_sum = sum(int(d) for d in n if int(d) % 2 != 0) print(odd_sum) |
π Explanation
Traverse each digit and check if itβs odd using % 2 != 0, then add to the total.
β Problem 11: Transpose of a Matrix
π Problem Statement
Find the transpose of the given matrix.
π’ Input
- First line: Two integers r c (rows and columns)
- Next r lines: Each line has c integers
π§Ύ Output
- The transposed matrix (columns become rows)
β Example
Input:
2 3
1 2 3
4 5 6
Output:
1 4
2 5
3 6
π£Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int r = sc.nextInt(), c = sc.nextInt(); int[][] mat = new int[r][c]; for (int i = 0; i < r; i++) for (int j = 0; j < c; j++) mat[i][j] = sc.nextInt(); for (int i = 0; i < c; i++) { for (int j = 0; j < r; j++) System.out.print(mat[j][i] + " "); System.out.println(); } } } |
1 2 3 4 5 |
r, c = map(int, input().split()) matrix = [list(map(int, input().split())) for _ in range(r)] transpose = [[matrix[i][j] for i in range(r)] for j in range(c)] for row in transpose: print(*row) |
π Explanation
Transpose means flipping rows to columns. We switch matrix[i][j] to matrix[j][i].
β Problem 12: Matrix Multiplication
π Problem Statement
Multiply two matrices A and B and print the result.
π’ Input
- First line: Two integers r1 c1 (rows and columns of A)
- Next r1 lines: c1 integers each (Matrix A)
- Then: Two integers r2 c2 (rows and columns of B)
- Next r2 lines: c2 integers each (Matrix B)
π§Ύ Output
- Resultant matrix after multiplying A and B
β Example
Input:
2 2
1 2
3 4
2 2
5 6
7 8
Output:
19 22
43 50
π£Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int r1 = sc.nextInt(), c1 = sc.nextInt(); int[][] A = new int[r1][c1]; for (int i = 0; i < r1; i++) for (int j = 0; j < c1; j++) A[i][j] = sc.nextInt(); int r2 = sc.nextInt(), c2 = sc.nextInt(); int[][] B = new int[r2][c2]; for (int i = 0; i < r2; i++) for (int j = 0; j < c2; j++) B[i][j] = sc.nextInt(); if (c1 != r2) { System.out.println("Cannot multiply"); return; } int[][] C = new int[r1][c2]; for (int i = 0; i < r1; i++) for (int j = 0; j < c2; j++) for (int k = 0; k < c1; k++) C[i][j] += A[i][k] * B[k][j]; for (int[] row : C) { for (int val : row) System.out.print(val + " "); System.out.println(); } } } |
1 2 3 4 5 6 7 8 9 10 11 |
r1, c1 = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(r1)] r2, c2 = map(int, input().split()) B = [list(map(int, input().split())) for _ in range(r2)] if c1 != r2: print("Cannot multiply") else: result = [[sum(A[i][k] * B[k][j] for k in range(c1)) for j in range(c2)] for i in range(r1)] for row in result: print(*row) |
π Explanation
Standard matrix multiplication: A[i][k] * B[k][j] for all valid k, summed over.
β Problem 13: Check Balance of Parentheses
π Problem Statement
Check if the parentheses in a string are balanced (( ), { }, [ ]).
π’ Input
- A string containing brackets
π§Ύ Output
- Print Balanced or Not Balanced
β Example
Input:
({[]})
Output:
Balanced
π£Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import java.util.*; public class Main { public static boolean isBalanced(String s) { Stack<Character> stack = new Stack<>(); Map<Character, Character> pairs = Map.of(')', '(', '}', '{', ']', '['); for (char ch : s.toCharArray()) { if ("({[".indexOf(ch) >= 0) stack.push(ch); else if (")}]".indexOf(ch) >= 0) { if (stack.isEmpty() || stack.pop() != pairs.get(ch)) return false; } } return stack.isEmpty(); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(isBalanced(sc.nextLine()) ? "Balanced" : "Not Balanced"); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
def is_balanced(expr): stack = [] pair = {')': '(', ']': '[', '}': '{'} for ch in expr: if ch in '([{': stack.append(ch) elif ch in ')]}': if not stack or stack[-1] != pair[ch]: return False stack.pop() return not stack print("Balanced" if is_balanced(input()) else "Not Balanced") |
π Explanation
Use a stack to match opening and closing brackets. Ensure stack is empty at end.
π¨ Wipro Overview!
Curious about how Wipro’s selection process works, the rounds involved, and other key details? Donβt miss this complete breakdown:
π https://nextgenkodinghub.in/wipro-overview/
Wishing you the best of luck! πΌβ¨