The problem statement is an integral part of creating a coding question. A good problem statement should comprise a clear and detailed problem description, at least one sample test case with explanation, and constraints of the problem.
Write a program that reads in a string and finds the first non-repeated character in that string. Treat the characters as case sensitive. Therefore, "a" and "A" are different. You will be required to complete a given function nonRepeated.
There is one sentence in the input that contains String Str.
Sample Test Case with Explanation
A single character that represents the first character in Str that is not repeated.
When creating a problem statement, be mindful of the following:
- Problem Description
- Variable naming convention:
- The variables in the problem statement must match those in the code stubs. If you refer to a variable in the problem statement as "N", it should be referred as "N" (and not "n") in the code stubs as well.
- All variable names and function names should be italicized. For instance, nonRepeated is italicized in the above example.
- Terminology Usage: Be specific and clear when you write a problem statement to avoid any ambiguity. For example: When you have to refer to “binary search tree”; do not use “tree” or “binary tree”, but instead use the "binary search tree" phrase.
- Input and Output format
To ensure a smooth experience for the candidates, you must specify the input and output format with clarity while defining the problem statement.
Unless, you want the candidates to figure out all possible constraints of a problem, you should mention these constraints clearly.
For example: If the code has to read a number as an input, specify the range of that number. This will help the candidate to decide if int, long int, or long long int has to be used. If the input is a string, specify if the special characters such as ? @ , . ^ % are also present in the string. You can also specify if it contains consecutive spaces.
- Sample Test Case with Explanation
A sample test case, with input and expected output, is strongly recommended to explain the problem statement to the candidates with clarity.