FastPrepImplement Printf
Problems/Implement Printf

Implement Printf

NVIDIA logoNVIDIA● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an NVIDIA onsite interview for a full-time role. The report asks for printf but does not say which directives it must support or the edge rules. Here we use a small subset with a fixed outcome.

Our version is about 75% the same as the reported question.

Write a small text-formatting function, like a simple printf. You get a string pattern and a list of strings values. In this exercise, the pattern can use only three codes: %s, %d, and %%.

  • Every other character in pattern is copied to the output as it is.
  • %s takes the next string from values and puts it in exactly as written.
  • %d takes the next string, which holds a signed 32-bit decimal integer. Write that number in its standard decimal form: drop a leading plus sign and any extra leading zeros, and write zero as 0.
  • %% writes one percent sign and takes no value.
  • Only the codes in the original pattern are read. A percent sign inside an inserted value is plain output text and is never read as a code.

Return the resulting string. Every pattern is valid: each percent sign in it is part of one of the three two-character codes above. The number of %s and %d codes together equals values.length. Width, precision, and other codes are not part of this exercise.

Function

formatPrintf(pattern: String, values: String[]) → String

Examples

Example 1

pattern = "%s scored %d%%"values = ["Ada","+007"]return = "Ada scored 7%"

%s puts in Ada. %d reads the next value, drops its plus sign and leading zeros, and writes 7. The final %% adds one percent sign at the end.

Example 2

pattern = "[%s] %d"values = ["%d%%","-0000"]return = "[%d%%] 0"

%s puts in the value %d%% exactly as written. Those percent signs are now plain text, so they are not read again. Then %d reads negative zero with extra zeros and writes it as 0.

Example 3

pattern = "%%%%"values = []return = "%%"

The pattern is two %% codes in a row. Each one writes a single percent sign and takes no value, so the result is two percent signs.

Constraints

  • 0 <= pattern.length <= 10^5.
  • 0 <= values.length <= 10^5.
  • All strings contain only printable ASCII characters; an argument used by %s may be empty.
  • An argument used by %d contains an optional + or - followed by between 1 and 10 decimal digits, and its value lies from -2147483648 through 2147483647.
  • The total number of characters across all values is at most 10^5, and the returned string has at most 2 * 10^5 characters.

More NVIDIA Onsite Interview questions

  • Check Endianness Of A Byte ArrayONSITE INTERVIEW · Seen Sep 2026
  • Implement MallocONSITE INTERVIEW · Seen Sep 2026
  • Merge Two Arrays Into Sorted OrderONSITE INTERVIEW · Seen Sep 2026
  • Middle Node Of A Linked ListONSITE INTERVIEW · Seen Sep 2026
  • Ping Reply TrackingONSITE INTERVIEW · Seen Sep 2026
  • Reverse A StringONSITE INTERVIEW · Seen Sep 2026
  • Maximum Fish in a GridONSITE INTERVIEW · Seen Sep 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • First Register Overflow TickONSITE INTERVIEW · Seen May 2024
  • Two-Egg DroppingONSITE INTERVIEW · Seen May 2024

Similar questions at other companies

  • Shortest Uncommon SubstringAirbnb · ONSITE INTERVIEWAirbnb interview questions
  • Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
  • Longest Substring Without Repeating CharactersOracle · ONSITE INTERVIEWOracle interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Longest Substring Without Repeating CharactersSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Classify Password StrengthHackerRank · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
  • Sliding Items on a Circular RingIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
  • Longest Substring Without Repeating CharactersMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA OA: What It Tests (2026)
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public String formatPrintf(String pattern, String[] values) {
        // Write your code here.
    }
}
Checking account…