Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python first unique character A unique character is one that appears only once in a string. Given a string consisting of lowercase English letters

in python

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

Function Description

Complete the function

getUniqueCharacter in the

editor below.

getUniqueCharacter has the

following parameter(s):

strings: a string

Returns

int: either the 1-based index

or -1

constraints

1 ? length of s ? 10^5

the string s consist of lowercase english letters only

Input Format For

Custom Testing

The first line contains a

strife, s.

Sample Input For Custom

Testing

hackthegame

Sample Output

3

Explanation

The unique characters are

[c, k, t, g, m]out of which

the character c occurs first, at index 3

Step by Step Solution

3.47 Rating (163 Votes )

There are 3 Steps involved in it

Step: 1

Intro In Python a dictionary is a collection of keyvalue pairs It is an unordered data structure that stores data in a collection of keyvalue pairs we ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probability And Statistics For Engineering And The Sciences

Authors: Jay L. Devore

9th Edition

1305251806, 978-1305251809

More Books

Students also viewed these Programming questions