Virtusa Previous Year Coding Questions
Are you preparing for a placement at Virtusa?
Whether you're targeting the Coder or Power Coder role, this guide contains real Virtusa coding questions asked in recent campus and off-campus drives. From pattern printing to dynamic programming, we've compiled actual questions from previous years, shared by candidates who cracked the test.
Virtusa is known for its competitive coding rounds, especially in their online assessments. If you're aiming to clear Virtusa’s hiring process in 2024 or 2025, these questions will give you the idea you need.
✅ Suitable for B.Tech, MCA, and CS/IT students
✅ Covers coding round 1, technical interviews, and final assessments
✅ Includes problems on Arrays, Strings, Recursion, DP, Hashing, and more
Easy Level Questions
1. Reverse Array
Problem Statement: Write a function that returns the reverse of the input array.
Input Format:
- First line: An integer n (where n > 0), representing the size of the array
- Second line: n space-separated integers representing the elements of the array
Output Format: Print the array elements in reverse order.
Sample Input:
3
1 2 3
Sample Output:
3 2 1
Explanation: The reverse of the array {1, 2, 3} is {3, 2, 1}.
2. Remove Duplicates from String
Problem Statement: Write a function to remove all duplicate characters from a given string while preserving the original order of characters. When duplicates occur, the later occurrence(s) should be removed.
Input Format: A single input string.
Output Format: Return the modified string with duplicates removed (keeping only the first occurrence of each character).
Sample Input:
CsharpstarZ
Sample Output:
CsharptZ
3. Eliminate Duplicates in Sorted Array
Problem Statement: Given a sorted array, remove duplicates in-place and return the new length.
Input Format: A sorted array of integers.
Output Format: Return the new length after removing duplicates.
Example:
Input: arr = [1, 1, 2, 2, 3]
Output: 3 (array becomes [1, 2, 3])
4. Reverse Individual Words
Problem Statement: Reverse each word in a given string while keeping the word order intact.
Input Format: A string containing words separated by spaces.
Output Format: String with each word reversed individually.
Example:
Input: "Hello World"
Output: "olleH dlroW"
Medium Level Questions
5. Last Digit of Power
Problem Statement: Given a number N and another number K, find the last digit number formed when N is raised to the power K. Note: The values of N and K can be very large.
Input Format:
- First line: Number N
- Second line: Number K
Output Format: Return the last digit of N^K.
Sample Input:
3
2
Sample Output:
9
6. Special Dish Problem
Problem Statement: Monica needs to make a special dish for Joey. A dish is special if:
- It contains only the special ingredients '1', '2', and '3'
- These ingredients appear in exactly equal proportions
- The original order of ingredients cannot be changed
Input Format:
- First line: A string representing the list of ingredients
- Second line: The size of the string
Output Format: Return the number of ways to make a special dish.
Sample Input:
0123
4
Sample Output:
1
7. Count Distinct Years
Problem Statement: The United Nations Organization released a document containing important historical events with dates in 'DD-MM-YYYY' format. Write a function to count the total number of distinct years referenced in the document.
Input Format: A single string containing the document text.
Output Format: Return the count of distinct years found in all dates.
Sample Input:
UN was established on 24-10-1945. India got freedom on 15-08-1947.
Sample Output:
2
8. Most Frequent Character
Problem Statement: Given a string, find the character that appears most frequently. If multiple characters have the same maximum frequency, return 0. Otherwise, return the maximum count.
Input Format: A single input string.
Output Format:
- Return the count of the most frequent character if it's unique
- Return 0 if multiple characters share the highest frequency
Examples:
Input 1: Abcadr
Output 1: 2
Input 2: abcabc
Output 2: 0
9. Array Rotation (Anti-clockwise)
Problem Statement: Given an array and a number k, rotate the array anti-clockwise (left rotation) k times and return the resulting array.
Input Format:
- Array elements (space-separated or continuous numbers)
- Rotation count k
Output Format: The rotated array
Examples:
Input: 12345 k = 2
Output: 34512
Input: 10 20 30 40 50 k=3
Output: 40 50 10 20 30
10. Maximum Subarray Sum (Kadane's Algorithm)
Problem Statement: Given an array of integers, find the maximum sum of any contiguous subarray.
Input Format: An array of integers.
Output Format: Return the maximum sum.
Example:
Input: arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output: 6 (subarray [4, -1, 2, 1])
11. Four-Digit Perfect Squares with Even Digits
Problem Statement: Write a program to find all four-digit numbers that are perfect squares and have all digits even (0, 2, 4, 6, 8).
Input Format: No input required.
Output Format: All four-digit perfect squares with all even digits.
Example:
Output: 6400 (since 80^2 = 6400, and digits 6, 4, 0, 0 are all even)
12. Substring Check
Problem Statement: Given two strings A and B, check if B is a substring of A.
Input Format: Two strings A and B.
Output Format: Return True if B is substring of A, False otherwise.
Example:
Input: A = "HelloWorld", B = "World"
Output: True
13. Decode String
Problem Statement: Decode a string recursively encoded as count followed by substring in brackets.
Input Format: Encoded string with pattern like "3[a]2[bc]"
Output Format: Decoded string.
Example:
Input: "3[a]2[bc]"
Output: "aaabcbc"
14. Cryptarithm/Alphabetic Coding
Problem Statement: Solve a cryptarithm like SATURN + URANUS = PLANETS, where each letter represents a unique digit, and print the letter-digit mappings.
Input Format: A cryptarithm equation.
Output Format: Valid digit assignments for each letter.
Example:
Input: SATURN + URANUS = PLANETS
Output: Valid digit assignments (e.g., S=9, A=1, T=7, etc.)
Hard Level Questions (Dynamic Programming)
15. Longest Increasing Subsequence
Problem Statement: Given an integer array A, find the length of its longest increasing subsequence (LIS). A LIS is a subsequence where elements are in strictly increasing order.
Input Format:
- First line: Integer n (1 ≤ n ≤ 1000), size of array
- Second line: Integer array A with n elements
Output Format: Return the length of the longest increasing subsequence.
Sample Input:
3
1 3 2
Sample Output:
2
Explanation: The longest increasing subsequences in {1, 3, 2} are {1, 2} and {1, 3}, both of length 2.
Advanced Example:
Input: arr = [10, 9, 2, 5, 3, 7, 101, 18]
Output: 4 (subsequence [2, 3, 7, 101])
16. Knapsack Problem
Problem Statement: Given weights and values of n items, select items to include in a knapsack of capacity W to maximize total value.
Input Format:
- Array of values
- Array of weights
- Knapsack capacity W
Output Format: Maximum value that can be obtained.
Example:
Input: values = [60, 100, 120], weights = [10, 20, 30], W = 50
Output: 220 (select items with values 60 and 100)
Tips for Success
- Practice Time Complexity: Focus on optimizing solutions
- Edge Cases: Always consider boundary conditions
- Input Validation: Handle invalid inputs gracefully
- Code Readability: Write clean, well-commented code
- Test Cases: Create comprehensive test scenarios
Common Topics to Focus On
- Arrays & Strings: Manipulation, searching, sorting
- Dynamic Programming: LIS, Knapsack, subsequences
- Mathematical Problems: Number theory, combinatorics
- Pattern Matching: String algorithms, regex
- Data Structures: Implementation and usage
- Algorithm Design: Greedy, divide-and-conquer, backtracking
Join our WhatsApp channel for more updates!
Explore previous year questions from top companies to boost your placement prep: