Accenture Coding Questions: 4 Patterns with Solved Dry Runs

Stop memorising company-question lists. Learn four reusable coding patterns through precise examples involving strings, arrays, digits, and matrices.

KnowledgeGate Team

Exam prep & CS education

Updated 2 Oct 20265 min read

Memorising a long company-question list does not prepare you for the next variation. A better approach is to recognise the structure beneath the wording. This guide teaches four reusable patterns, each with an exact input, dry run, edge case, and complexity check. Use the overall Accenture rounds and study plan for the wider path, and the Placement Preparation category for related practice.

What Accenture officially confirms about technical assessments

According to Accenture's current recruiting FAQ, some roles use an online activity to assess technical skills, problem solving, logical reasoning, and applied knowledge. The exact assessment depends on the role, so confirm the allowed tools, timing, and task format in your test invitation or role description.

The four patterns below form a practice framework for coding-round readiness. If you also need to prepare for stages beyond coding, follow the broader plan linked above.

Pattern 1: Frequency maps and ordered string scans

Problem: Given a lowercase string, return its first character that occurs exactly once. Return -1 if none exists.

For input swiss, make two passes. The first pass builds the counts s: 3, w: 1, and i: 1. The second pass preserves the original order. At index 0, s has count 3, so continue. At index 1, w has count 1, so return w. Iterating over the frequency-map keys alone does not prove which unique character appeared first in the input.

Code
function firstUnique(text):
    counts = empty map
    for character in text:
        counts[character] += 1
    for index from 0 to length(text) - 1:
        if counts[text[index]] == 1: return text[index]
    return -1

The time complexity is O(n), and the extra space is O(k), where k is the number of distinct characters. Check the boundaries too: aabb returns -1, z returns z, and an empty string returns -1.

Pattern 2: One-pass array state with duplicates

Problem: Return the second-largest distinct integer in an array. If fewer than two distinct values exist, report no answer.

Use [7, 4, 9, 9, 2, 7] and track (largest, second). Start at (unset, unset). After 7, the state is (7, unset). After 4, it is (7, 4). The first 9 promotes 9 and demotes 7, giving (9, 7). The duplicate 9 changes nothing. The 2 is smaller than both stored values. The final 7 already equals second, so the final answer is 7.

First ignore a value equal to either stored distinct value. If it is greater than largest, move the old largest to second, then store the new largest. Otherwise, replace second only if the value lies strictly between the two. This order prevents a duplicate maximum from becoming the second-largest value.

The scan takes O(n) time and O(1) extra space. [5, 5] has no answer, while [-3, -8, -5] returns -5.

Six-column state table for second-largest distinct value. Columns are scanned value 7, 4, 9, 9, 2, 7; largest row 7, 7, 9, 9, 9, 9; second row unset, 4, 7, 7, 7, 7; action row set largest, set second, promote 9 and demote 7, ignore duplicate, ignore smaller, ignore duplicate; final badge second-largest distinct = 7.

Pattern 3: Digit extraction and accumulators

Problem: For a non-negative integer, return the absolute difference between the sum of its even digits and the sum of its odd digits.

For 583120, repeated % 10 and integer division by 10 extract the digits from right to left as 0, 2, 1, 3, 8, 5. In readable order, they are 5, 8, 3, 1, 2, 0. The even sum is 8 + 2 + 0 = 10, and the odd sum is 5 + 3 + 1 = 9. Therefore, the result is |10 - 9| = 1.

For d digits, the method takes O(d) time and O(1) space. Zero is even and must be classified even though adding it does not change the sum. The smallest edge case, input 0, returns 0. If the function accepts signed input, normalise it with absolute value before extracting digits.

Pattern 4: Matrix boundary traversal without double-counting corners

Problem: Return the sum of the boundary elements of a rectangular matrix.

Use this 3 x 4 matrix:

1

2

3

4

5

6

7

8

9

10

11

12

The top row contributes 1 + 2 + 3 + 4 = 10. The bottom row contributes 9 + 10 + 11 + 12 = 42. Only the side cells from the middle row remain, so they contribute 5 + 8 = 13. The boundary sum is 10 + 42 + 13 = 65. Values 6 and 7 are interior cells, and each corner is included once.

A clear full-scan rule is to include (r,c) when r == 0 || r == R - 1 || c == 0 || c == C - 1. It takes O(RC) time and O(1) extra space. A perimeter-only traversal visits fewer cells, but it needs separate care for a matrix with one row or one column.

Boundary-sum map for the exact 3 x 4 matrix. Show rows 1 2 3 4, 5 6 7 8, 9 10 11 12; highlight boundary values 1,2,3,4,5,8,9,10,11,12; leave interior values 6,7 unhighlighted; label grouped totals top = 10, middle sides = 13, bottom = 42, and final boundary sum = 65; add a small warning label corners counted once.

Turn an unfamiliar statement into one of the four patterns

Before coding, ask four questions:

  1. Is the answer driven by counts? Use a frequency map and preserve any required input order.

  2. Is it an ordered scan with a small amount of state? Carry only the values needed for the next decision.

  3. Can the number be decomposed digit by digit? Use remainder and integer division with accumulators.

  4. Are coordinates or boundaries the real structure? Define the included rows and columns before traversing.

Write the input-output contract first. Then choose a baseline solution, calculate its complexity, and design three tests: a normal case, a boundary case, and a duplicate or empty case. Words such as distinct matter. Without that condition, someone might call the repeated 9 in [7, 4, 9, 9, 2, 7] the second answer. With distinct values required, the correct answer is 7. Use triage and time-boxing during the round when several unfamiliar problems compete for your time.

Traps that turn a correct idea into a failed submission

Pair every common trap with a direct fix:

  • Define duplicate semantics before coding, especially for words such as distinct.

  • Test negative values instead of assuming every array contains only positive integers.

  • Scan the original string when character order matters, rather than trusting map-key order.

  • Use one boundary rule so matrix corners are not counted twice.

  • Check the actual data structure before stating time and space complexity.

Use an integer type wide enough for possible sums. Keep input parsing separate from the solution function, and avoid hidden global state. Run the supplied example exactly. Before submitting: compile, test the stated sample, test one edge case, inspect output formatting, then submit.

Short version and next practice step

Count for frequency problems, carry minimal state for ordered arrays, peel digits for numeric tasks, and model coordinates for matrices. Recognising these structures is more durable than memorising question lists.

Use the Accenture Superset course for company-focused preparation, or Coding for Placements for broader language and coding practice. Then re-code all four examples without notes. Change one input in each to aabb, [-3, -8, -5], 0, and a 1 x 4 matrix [2, 4, 6, 8]. Explain each expected output before running the program.