ACCENTURE 2026 CAMPUS HIRING
Round 3 — Backend Coding (DSA) & SQL Preparation Guide
Languages: Python / Java / C# | Difficulty: LeetCode Easy-Medium | 3 DSA + SQL questions
Before You Write Code — Critical Setup
CAUTION: Java users: scroll to the top of the template FIRST. Comment out or delete the line that says throw new
Exception(...) otherwise your correct code will always fail.
• Read the problem statement twice. Note the input format (N then array, or just array?)
• Check all provided examples — at least 2. If your approach doesn't match both, rethink
• Write your solution for the example case first, then generalise
• Python is recommended — fewest lines, no type casting, built-in max/min/sum/sorted
DSA Pattern 1: Sliding Window / Range Sum
This is the most tested pattern. The cave energy problem from the actual exam uses this exact approach.
The Cave Energy Problem (Actual Exam Question)
Problem: Given N caves with energies in array A, for each cave i compute the sum of A[j] for j from max(0, i-2) to
i. Return the total of all these sums.
Python solution
def cave_energy(N, A):
total = 0
for i in range(N):
start = max(0, i - 2) # window starts 2 steps back (or 0)
for j in range(start, i + 1): # inclusive of i
total += A[j]
return total
# Trace for N=3, A=[2,3,1]:
# i=0: start=max(0,-2)=0 -> j in [0,0] -> A[0]=2 -> total=2
# i=1: start=max(0,-1)=0 -> j in [0,1] -> A[0]+A[1]=5 -> total=7
# i=2: start=max(0,0)=0 -> j in [0,2] -> A[1]+A[2]=4 -> total=11
# Output: 11 ✓
Java solution
public static int caveEnergy(int N, int[] A) {
// throw new Exception(); <-- COMMENT THIS OUT
int total = 0;
for (int i = 0; i < N; i++) {
int start = [Link](0, i - 2);
for (int j = start; j <= i; j++) {
total += A[j];
}
}
return total;
}
General sliding window template
def sliding_window_sum(arr, K):
n = len(arr)
result = []
for i in range(n):
start = max(0, i - K + 1) # adjust K for the specific problem
window_sum = sum(arr[start:i+1])
[Link](window_sum)
return result
# Optimised version using prefix sums (O(1) per query):
def prefix_sum(arr):
prefix = [0] * (len(arr) + 1)
for i, v in enumerate(arr):
prefix[i+1] = prefix[i] + v
# sum from l to r (inclusive) = prefix[r+1] - prefix[l]
return prefix
DSA Pattern 2: String & Array Problems
Frequency Counting
Count characters / find most frequent
from collections import Counter
s = 'aabbbcc'
freq = Counter(s) # {'b': 3, 'a': 2, 'c': 2}
most_common = freq.most_common(1)[0] # ('b', 3)
# Manual version (no imports):
freq = {}
for c in s:
freq[c] = [Link](c, 0) + 1
Two Pointer Technique
Reverse array / check palindrome
def is_palindrome(s):
left, right = 0, len(s) - 1
while left < right:
if s[left] != s[right]:
return False
left += 1
right -= 1
return True
def reverse_array(arr):
left, right = 0, len(arr) - 1
while left < right:
arr[left], arr[right] = arr[right], arr[left]
left += 1; right -= 1
return arr
Sorting & Searching
Sort, binary search, find pairs
# Sort
[Link]() # in-place, ascending
[Link](reverse=True) # descending
sorted_arr = sorted(arr) # returns new list
# Binary search (arr must be sorted)
import bisect
idx = bisect.bisect_left(arr, target) # insertion point (left)
# Find pair that sums to target
def two_sum(arr, target):
seen = set()
for num in arr:
if target - num in seen:
return True
[Link](num)
return False
DSA Pattern 3: Number / Math Problems
Common Number Problems
GCD, prime check, digit extraction
import math
# GCD (Euclidean algorithm)
def gcd(a, b):
while b:
a, b = b, a % b
return a
# Or: [Link](a, b)
# LCM
def lcm(a, b):
return a * b // [Link](a, b)
# Prime check O(sqrt(n))
def is_prime(n):
if n < 2: return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0: return False
return True
# Digit sum
def digit_sum(n):
return sum(int(d) for d in str(abs(n)))
# Count digits / reverse number
digits = list(str(n)) # ['1','2','3'] from 123
reversed_n = int(str(n)[::-1]) # 321 from 123
Recursion Pattern
Fibonacci / factorial with memoization
# Factorial
def factorial(n):
if n <= 1: return 1
return n * factorial(n - 1)
# Fibonacci (naive)
def fib(n):
if n <= 1: return n
return fib(n-1) + fib(n-2)
# Fibonacci (with memoization — much faster)
from functools import lru_cache
@lru_cache(maxsize=None)
def fib_memo(n):
if n <= 1: return n
return fib_memo(n-1) + fib_memo(n-2)
# Or iterative (O(n) time, O(1) space)
def fib_iter(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a
Python Data Structure Quick Reference
Concept Explanation / Example
List (array) arr = [1,2,3]. append(x), pop(), pop(i), insert(i,x), len(arr), arr[i], arr[-1]=last,
arr[1:3]=slice
Set s = {1,2,3}. add(x), remove(x), discard(x). s1 & s2 (intersection), s1 | s2
(union), x in s
Dict (hashmap) d = {'a':1}. d[k], [Link](k,default), [Link](), [Link](), [Link](), k in d
Stack (use list) stack = []. push: [Link](x). pop: [Link](). peek: stack[-1]
Queue from collections import deque. q = deque(). appendleft(x), append(x),
popleft(), pop()
Heap (min) import heapq. [Link](h, x), [Link](h). h[0] = min
element
Max heap Push negatives: [Link](h, -x). Pop: -[Link](h)
sorted() sorted(arr) returns new list. sorted(arr, key=lambda x: -x) = descending
enumerate() for i, v in enumerate(arr): — gives index + value
zip() for a, b in zip(list1, list2): — iterate two lists in parallel
TIP: For Accenture, the most likely data structures tested are: dict (for frequency counting), list (sliding window), and
simple variables (accumulators). You almost never need a tree or graph.
SQL Section — Complete Prep Guide
Topics tested: JOINs, GROUP BY, HAVING, ORDER BY, LIMIT, basic aggregation. No window functions or
stored procedures confirmed.
SQL Clauses — Execution Order (Critical!)
SQL clauses execute in this order regardless of how you write them:
1. FROM / JOIN — select and combine tables
2. WHERE — filter rows BEFORE grouping
3. GROUP BY — aggregate into groups
4. HAVING — filter groups AFTER aggregation
5. SELECT — choose columns
6. ORDER BY — sort the result
7. LIMIT / OFFSET — restrict row count
CAUTION: WHERE cannot use aggregate functions (SUM, COUNT, AVG). Use HAVING for that. This is the most
common MCQ trap.
JOIN Types — Visual Reference
Concept Explanation / Example
INNER JOIN Returns rows that have matches in BOTH tables. Most common join
LEFT JOIN Returns ALL rows from left table + matching rows from right. NULL if no
match on right
RIGHT JOIN Returns ALL rows from right table + matching rows from left. NULL if no
match on left
FULL OUTER JOIN Returns ALL rows from both tables. NULLs where no match exists
CROSS JOIN Every row from left combined with every row from right. N x M result rows
SELF JOIN Joining a table with itself. Use aliases: employees e1, employees e2
Essential SQL Templates
SELECT with WHERE, ORDER BY, LIMIT
SELECT column1, column2
FROM table_name
WHERE condition
ORDER BY column1 ASC, column2 DESC
LIMIT 10;
-- Find employees with salary > 50000
SELECT name, salary
FROM employees
WHERE salary > 50000
ORDER BY salary DESC;
INNER JOIN — most tested
SELECT [Link], d.department_name
FROM employees e
INNER JOIN departments d
ON e.department_id = [Link]
WHERE d.department_name = 'Engineering';
-- Three table join
SELECT [Link], d.dept_name, p.project_name
FROM employees e
JOIN departments d ON e.dept_id = [Link]
JOIN projects p ON e.proj_id = [Link];
GROUP BY + HAVING (aggregate filtering)
-- Count employees per department
SELECT department_id, COUNT(*) AS emp_count
FROM employees
GROUP BY department_id;
-- Only departments with more than 5 employees
SELECT department_id, COUNT(*) AS emp_count
FROM employees
GROUP BY department_id
HAVING COUNT(*) > 5;
-- Average salary per department, only if avg > 60000
SELECT department_id, AVG(salary) AS avg_sal
FROM employees
GROUP BY department_id
HAVING AVG(salary) > 60000
ORDER BY avg_sal DESC;
LEFT JOIN — find unmatched rows
-- Find employees without a department
SELECT [Link], d.department_name
FROM employees e
LEFT JOIN departments d ON e.dept_id = [Link]
WHERE [Link] IS NULL; -- NULL on right = no match
-- Find products with no orders
SELECT p.product_name
FROM products p
LEFT JOIN orders o ON [Link] = o.product_id
WHERE [Link] IS NULL;
Subqueries & IN / EXISTS
-- Employees earning more than average
SELECT name, salary
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
-- Employees in departments located in 'Mumbai'
SELECT name
FROM employees
WHERE department_id IN (
SELECT id FROM departments WHERE city = 'Mumbai'
);
-- Using EXISTS (faster for large tables)
SELECT [Link]
FROM employees e
WHERE EXISTS (
SELECT 1 FROM orders o WHERE o.emp_id = [Link]
);
Aggregate Functions — Quick Reference
Concept Explanation / Example
COUNT(*) Count all rows including NULLs
COUNT(col) Count non-NULL values in column
COUNT(DISTINCT col) Count unique non-NULL values
SUM(col) Sum of all non-NULL values
AVG(col) Average of all non-NULL values (ignores NULL)
MAX(col) / MIN(col) Largest / smallest non-NULL value
GROUP_CONCAT(col) Concatenate values in a group (MySQL). STRING_AGG in PostgreSQL
String & Date Functions (Common in MCQs)
Concept Explanation / Example
UPPER(str) / LOWER(str) Convert case
LENGTH(str) Number of characters
SUBSTRING(str, start, len) Extract part of string. 1-indexed
TRIM(str) Remove leading and trailing spaces
CONCAT(s1, s2) Join strings. CONCAT('Hello', ' ', 'World')
LIKE Pattern matching. % = any chars, _ = one char. LIKE 'A%' = starts with A
NOW() / CURDATE() Current datetime / date
YEAR(date) / MONTH(date) Extract parts of a date
DATEDIFF(d1, d2) Days between two dates
SQL MCQ Traps to Watch For
• WHERE vs HAVING: WHERE filters rows (before GROUP BY), HAVING filters groups (after GROUP BY)
• COUNT(*) counts ALL rows including duplicates. COUNT(col) ignores NULLs
• NULL comparisons: NULL = NULL is FALSE. Use IS NULL or IS NOT NULL
• DISTINCT applies to all selected columns together, not just the first one
• ORDER BY executes AFTER SELECT — you can ORDER BY a column alias
• INNER JOIN excludes unmatched rows from both sides — if you need all rows, use LEFT/RIGHT JOIN
Coding Round — Exam Day Checklist
Before Starting Any Coding Problem
8. Read the full problem statement, including Input Specification and Output Specification
9. Study all provided examples — note N range and array sizes
10. Plan: will a simple O(N^2) loop be fast enough? For N < 1000 it almost always is
11. Java: immediately comment out throw new Exception() at the top of the template
12. Write and test on Example 1. Then verify on Example 2 before submitting
Common Mistakes to Avoid
• Off-by-one in loops: double check if range is 0 to N-1 or 0 to N
• Integer overflow: if N is large and you're multiplying, use long in Java
• Forgetting edge cases: empty array (N=0), N=1, all same values, negative numbers
• Reading input wrong: if there are multiple test cases, loop over them all
• Printing extra whitespace or lines — output format must match exactly
TIP: Partial credit exists — even if your solution fails some test cases, passing the example cases gives marks. Always
submit something.