Virtusa coding round questions
Last updated 2026-11-19
Virtusa builds and maintains software for banks, insurers, healthcare providers and public-sector clients, and a lot of that code is Java. Candidates usually report a first-stage test that mixes aptitude with a short programming section pitched at easy to medium difficulty. Virtusa has not published a syllabus that we can cite, so treat everything below as practice in the reported style rather than a preview of any actual paper.
The twelve problems borrow their stories from ledgers, claims and appointment books, because that is the kind of data a services engineer ends up touching. Java is written first and Python second, and every answer states complexity plus the slip that most often costs marks. For the conversational rounds, read Virtusa interview questions.
| Round style (commonly reported) | Aptitude plus a technical and coding section |
|---|---|
| Practice difficulty | Easy to medium, with one SQL query |
| Code shown | Java first, Python second, SQL where relevant |
Why the problems here are all money and patients
Application-services work is mostly about records: a transaction list, a batch of insurance claims, a day of clinic appointments. When a test setter wants a quick programming question, the story is usually one of these. If you recognise the pattern under the story, whether it is a running total, a set lookup or an interval merge, the problem shrinks to something you have solved before.
Read the statement for the data type of money. A balance stored as an int can overflow on a large ledger, so the Java answers below use long for amounts. Say this aloud or in a comment; it shows you think about the production use of the function, not only the sample input.
Java habits worth building before the test
Practise with the standard library only: HashSet, HashMap, ArrayList, Arrays.sort with a comparator, StringBuilder and Collections. Writing a comparator lambda from memory saves a minute on every sorting question. Avoid autoboxing in tight loops when a primitive array will do, and remember that comparing two Integer objects with == fails outside the small cached range.
If the platform lets you choose Python, use it for string-heavy questions and keep Java for anything where the statement mentions classes. The Java interview guide covers the language topics that tend to come up in the technical round.
Hiring status
This site holds no sourced Virtusa statement on fresher numbers, dates or eligibility, so none are given. Take the real test pattern from your invitation email and Virtusa's own careers site.
Virtusa coding round questions: questions with worked answers
1 A savings account starts with an opening balance and receives a list of signed transactions. Return the index of the first transaction that leaves the balance below zero, or -1.
easyRunning total. Add each transaction to the balance in order and stop at the first time it drops under zero. One pass, O(n) time, O(1) space. Use a long for the balance, since many large deposits can overflow an int. The usual slip is checking the balance before applying the transaction, which reports the index one too late.
javaclass Ledger { static int firstOverdraft(long opening, long[] txns) { long bal = opening; for (int i = 0; i < txns.length; i++) { bal += txns[i]; if (bal < 0) return i; } return -1; } }pythondef first_overdraft(opening, txns): bal = opening for i, t in enumerate(txns): bal += t if bal < 0: return i return -12 Mask a card number for display so that only the last four digits are visible. Spaces and hyphens in the input must be ignored.
easyString clean-up. Strip separators first, then build asterisks for everything except the last four digits. Numbers of four digits or fewer are returned as they are. Time is O(n). The common error is masking the separators too, or slicing with a negative index on a string shorter than four characters, which silently returns the wrong part.
javaclass Mask { static String maskCard(String num) { String d = num.replaceAll("[ -]", ""); if (d.length() <= 4) return d; return "*".repeat(d.length() - 4) + d.substring(d.length() - 4); } }pythondef mask_card(num): d = num.replace(" ", "").replace("-", "") if len(d) <= 4: return d return "*" * (len(d) - 4) + d[-4:]3 A clinic stores appointment blocks as [start, end] minute pairs. Merge the blocks that overlap or touch so the receptionist sees continuous busy periods.
mediumInterval merging. Sort by start time, then sweep: if the next start is at or before the end of the last merged block, extend that end to the larger value; otherwise open a new block. Sorting dominates, so O(n log n) time and O(n) output space. Forgetting to take the maximum of the two ends breaks the case where a short block sits fully inside a long one.
javaimport java.util.*; class Slots { static int[][] mergeSlots(int[][] slots) { Arrays.sort(slots, (a, b) -> Integer.compare(a[0], b[0])); List<int[]> out = new ArrayList<>(); for (int[] s : slots) { if (!out.isEmpty() && s[0] <= out.get(out.size() - 1)[1]) { int[] last = out.get(out.size() - 1); last[1] = Math.max(last[1], s[1]); } else { out.add(new int[]{s[0], s[1]}); } } return out.toArray(new int[0][]); } }pythondef merge_slots(slots): out = [] for s, e in sorted(slots): if out and s <= out[-1][1]: out[-1][1] = max(out[-1][1], e) else: out.append([s, e]) return out4 Given the list of claim IDs processed in order, return the first ID that appears a second time, or None if all are unique.
easySet membership. Walk the list and keep a set of IDs already seen; the first ID found in the set is the answer, because its second occurrence comes earliest. O(n) time and O(n) space. Counting every ID first and then picking one with count above one is wrong here, since it may return a duplicate whose second occurrence is later than another's.
javaimport java.util.*; class Claims { static Integer firstRepeat(int[] ids) { Set<Integer> seen = new HashSet<>(); for (int id : ids) { if (!seen.add(id)) return id; } return null; } }pythondef first_repeat(ids): seen = set() for x in ids: if x in seen: return x seen.add(x) return None5 Daily closing prices of a mutual fund unit are given in an array. What is the largest profit from buying on one day and selling on a later day? Return 0 if no profit is possible.
easyTrack the cheapest price seen so far while scanning, and at each day compute the profit if you sold then. Keep the maximum. O(n) time, O(1) space. Trying every pair is O(n^2). A frequent bug is taking the global minimum and global maximum separately, which can place the sale before the purchase.
javaclass Fund { static int maxProfit(int[] price) { int low = Integer.MAX_VALUE, best = 0; for (int p : price) { low = Math.min(low, p); best = Math.max(best, p - low); } return best; } }pythondef max_profit(price): low, best = float("inf"), 0 for p in price: low = min(low, p) best = max(best, p - low) return best6 Print a right-aligned number triangle for a given n, where row i holds the numbers 1 to i separated by single spaces.
easyPattern printing. For row i, emit n - i leading spaces and then the numbers 1..i. Total work is O(n^2) because that is the output size. Build each row in a StringBuilder before printing to avoid many small writes. The usual error is putting a trailing space after the last number, which some judges reject.
javaclass Pattern { static void triangle(int n) { for (int i = 1; i <= n; i++) { StringBuilder sb = new StringBuilder(); for (int s = 0; s < n - i; s++) sb.append(' '); for (int k = 1; k <= i; k++) { if (k > 1) sb.append(' '); sb.append(k); } System.out.println(sb); } } }pythondef triangle(n): for i in range(1, n + 1): print(" " * (n - i) + " ".join(str(k) for k in range(1, i + 1)))7 A hospital export line looks like "asha:67;ravi:34;meena:71". Count how many patients are older than 60.
easyDelimiter parsing. Split on the semicolon, then split each record on the colon and compare the age as an integer. O(n) in the length of the line. Skip empty records, which appear when the line ends with a semicolon, and parse the age with Integer.parseInt rather than comparing strings, because the text "7" is greater than "60" alphabetically.
javaclass Patients { static int countSenior(String line) { int count = 0; for (String rec : line.split(";")) { if (rec.isBlank()) continue; int age = Integer.parseInt(rec.split(":")[1].trim()); if (age > 60) count++; } return count; } }pythondef count_senior(line): count = 0 for rec in line.split(";"): if rec.strip(): if int(rec.split(":")[1]) > 60: count += 1 return count8 Given the day numbers on which a customer logged in to net banking, find the longest streak of consecutive days.
mediumHash set. Put all days in a set. Only start counting from a day whose predecessor is absent, then walk forward while the next day exists. Each day is visited at most twice, so O(n) time and O(n) space, better than sorting at O(n log n). Counting from every element rather than only from streak starts makes it quadratic.
javaimport java.util.*; class Streak { static int longestStreak(int[] days) { Set<Integer> set = new HashSet<>(); for (int d : days) set.add(d); int best = 0; for (int d : set) { if (set.contains(d - 1)) continue; int len = 1; while (set.contains(d + len)) len++; best = Math.max(best, len); } return best; } }pythondef longest_streak(days): s = set(days) best = 0 for d in s: if d - 1 not in s: n = 1 while d + n in s: n += 1 best = max(best, n) return best9 Encrypt a numeric PIN by adding a key k to every digit, wrapping around after 9, so 7 with key 5 becomes 2.
easyModular arithmetic on characters. Convert each character to its digit, add k, take the result modulo 10 and convert back. O(n). In Java do the arithmetic as c - '0' and add '0' again at the end, otherwise you add the key to the character code and land outside the digit range. A negative key needs ((x % 10) + 10) % 10.
javaclass Pin { static String shift(String pin, int k) { StringBuilder sb = new StringBuilder(); for (char c : pin.toCharArray()) { int d = ((c - '0' + k) % 10 + 10) % 10; sb.append((char) ('0' + d)); } return sb.toString(); } }pythondef shift(pin, k): return "".join(str((int(c) + k) % 10) for c in pin)10 Table loans(loan_id, customer_id, status). Write a query that lists customers holding more than one ACTIVE loan, with the count.
easyFilter before grouping. Use WHERE to keep only ACTIVE rows, group by customer and use HAVING to keep groups above one, since an aggregate cannot appear in WHERE. Using HAVING for the status test also works but is slower on a large table. Selecting a column that is neither grouped nor aggregated fails in strict SQL modes.
sqlSELECT customer_id, COUNT(*) AS active_loans FROM loans WHERE status = 'ACTIVE' GROUP BY customer_id HAVING COUNT(*) > 1 ORDER BY active_loans DESC, customer_id;11 n customers stand in a counter queue, numbered 1 to n. Starting from the front, every k-th customer in the circle gives up and leaves. Which customer is left at the end?
mediumThis is the Josephus problem. Simulating removals with a list costs O(n k) or O(n^2). The recurrence f(1) = 0, f(i) = (f(i-1) + k) mod i gives the zero-based survivor in O(n) time and O(1) space; add one at the end. For n = 5 and k = 2 the survivor is 3. Forgetting the final +1 for one-based numbering is the typical wrong answer.
javaclass Queue { static int lastStanding(int n, int k) { int pos = 0; for (int i = 2; i <= n; i++) pos = (pos + k) % i; return pos + 1; } }pythondef last_standing(n, k): pos = 0 for i in range(2, n + 1): pos = (pos + k) % i return pos + 112 A customer saves a positive amount every month, given as an array. Return the first month (1-based) in which the total saved reaches a goal, or -1 if it never does.
mediumPrefix sums plus binary search. All deposits are positive, so the prefix sums strictly increase and the first one at or above the goal can be found by binary search in O(log n) after an O(n) build. A plain loop is also O(n) and perfectly acceptable. Binary search would be invalid if deposits could be negative, so state that assumption.
javaclass Goal { static int firstMonth(int[] dep, long goal) { long[] pre = new long[dep.length]; long run = 0; for (int i = 0; i < dep.length; i++) { run += dep[i]; pre[i] = run; } int lo = 0, hi = dep.length - 1, ans = -1; while (lo <= hi) { int mid = lo + (hi - lo) / 2; if (pre[mid] >= goal) { ans = mid + 1; hi = mid - 1; } else lo = mid + 1; } return ans; } }pythonfrom itertools import accumulate from bisect import bisect_left def first_month(dep, goal): pre = list(accumulate(dep)) i = bisect_left(pre, goal) return i + 1 if i < len(pre) else -1
Frequently asked questions
How hard is the Virtusa coding round?
Candidates generally describe it as easy to medium, built around array, string and basic data-structure problems rather than advanced algorithms. Treat that as a pattern from reports, not a guarantee, and check your invitation.
Should I answer in Java or Python?
Use whichever you can write bug-free faster, as long as the platform allows it. Java suits roles that centre on enterprise Java; Python is quicker for string manipulation.
Will SQL come up in the test?
Technical sections for services roles often include a query or two, so practise GROUP BY with HAVING and basic joins alongside the coding problems.
How do I practise these twelve problems?
Attempt each on paper for ten minutes, type it, then run it on an empty input, a single element and a large input. Only then read the model answer.
Where can I find the official test format?
The invitation email and Virtusa's careers site are the only reliable sources. Pages like this one cannot confirm the current pattern.
Related guides
More in Company Interview Questions
- Virtusa interview questions and answers
- Visa coding round questions with solutions
- Visa interview questions with answers (software engineer, India)
- VMware Coding Round Questions with Solutions in Python and Java
- VMware Interview Questions and Answers for Systems and SDE Roles
- Walmart Coding Round Questions With Solutions
- Walmart Global Tech Interview Questions and Answers
- Wells Fargo coding round questions with solutions
- Wells Fargo interview questions with answers (technology roles)
- Wipro Coding Round Questions with Solutions
- Wipro Interview Questions for Freshers
- Workday Coding Round Questions With Solutions