FastPrepIndex of the First Non-Repeating Character
Problems/Index of the First Non-Repeating Character

Index of the First Non-Repeating Character

Visa logoVisa● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An August 4, 2022 Visa Staff Software Engineer online assessment report names the task of finding the index of the first non-repeating character, and a hash-map solution. It leaves out limits, the alphabet, and a function signature. Our version uses a reviewed fixed set of rules for the same task.

Given a non-empty string s, return the zero-based index of the first character whose total frequency in the string is exactly one.

If no such character exists, return -1. Character comparisons are case-sensitive.

Function

firstNonRepeatingIndex(s: String) → int

Examples

Example 1

s = "swiss"return = 1

The character s repeats, while w occurs once at index 1.

Example 2

s = "aabbc"return = 4

Only c has frequency one, and its index is 4.

Example 3

s = "aabb"return = -1

Every character repeats, so there is no qualifying index.

Constraints

  • 1 ≤ s.length ≤ 100000.
  • s contains printable ASCII characters.

More Visa Online Assessment questions

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Lock CodeOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
  • Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
  • Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
  • Count Valid Space-Delimited WordsOA · Seen Oct 2026
  • Earliest Common Meeting StartOA · Seen Oct 2026
  • Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
  • Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026

Similar questions at other companies

  • Branch with the Most FilesCapital One · OACapital One interview questions
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • First Non-Repeating CharacterAmazon · OA · ONSITE INTERVIEW
  • Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • Count Palindrome Addition ChoicesThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
  • Count Palindrome Addition ChoicesHudson River Trading · OAHudson River Trading interview questions
  • Count Phrases Formed by Anagram ReplacementWells Fargo · OAWells Fargo interview questions
  • Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int firstNonRepeatingIndex(String s) {
        // Write your code here.
    }

}
Checking account…