EV_First Unique Character asked in Infosys march 2022 on hackerrank platform


                                                 EV_First Unique Character



connect with me on
                                                 3. EV_First Unique Character

A unique character is one that appears only once in a string. Given a string consisting of lowercase English letters only, return the index of the first occurrence of a unique character in the string using 1-based indexing. If the string does not contain any unique character, return-1.

Example

s="statistics"

The unique characters are [a, c] among which a occurs first. Using 1-based indexing, it is at index 3.

Function Description

Complete the function getUnique Character in the editor below.

getUniqueCharacter has the following parameter(s):

string s: a string

Returns

int: either the 1-based index or -1

Constraints

• 1 s. length of ss 105

. The string s consists of lowercase English letters only.

►Input Format For Custom Testing

☛ Sample Case O

Constraints

• 1 length of ss 10³

• The string s consists of lowercase English letters only.

✓ Input Format For Custom Testing The first line contains a string, s.

Sample Case 0

Sample Input For Custom Testing

hackthegame

Sample Output

3

Explanation

The unique characters are [c, k tg m) out of which the character c occurs first, at index 3.

Sample Case 1

Sample Input For Custom Testing

falafal

Sample Output

-1

Explanation

All the characters present occur at least twice in the given string. There

are no unique characters.

Constraints

• 1 length of ss 10³

• The string s consists of lowercase English letters only.

✓ Input Format For Custom Testing

The first line contains a string, s.

Sample Case 0

Sample Input For Custom Testing

hackthegame

2

Sample Output

3

3

Explanation

The unique characters are [c, ktg m] out of which the character c occurs first, at index 3.

Sample Case 1

Sample Input For Custom Testing

falafal

Sample Output

-1

Explanation

All the characters present occur at least twice in the given string. There are no unique characters.







Practise on live C++ Compiler

connect with me on

Comments

Popular posts from this blog

EV Minimize Array Cost asked in Infosys- march 2022 (available in c++ only)

Harry and Porter asked in MountainBlue ,2022

For e-learning, various tutorials are provided to the students.