`{"id":"2115ac03-916d-43c5-bef4-73deab646c27","name":"First Non-repeating Character","description":"1. You are given a string.\r\n2. You have to find the index of the first non-repeating character in the given string.\r\n3. If no such character exists, print \"-1\".","inputFormat":"A string","outputFormat":"A number representing the index of the first non-repeating character.","constraints":"1 &lt;= length of the string &lt;= 10^5","sampleCode":{"cpp":{"code":"#include <iostream>\r\n#include <vector>\r\nusing namespace std;\r\n\r\nint solution(string &s)\r\n{\r\n \r\n}\r\n\r\nint main()\r\n{\r\n string s;\r\n cin >> s;\r\n solution(s);\r\n return 0;\r\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static int solution(String s) {\r\n\t\t// write your code here\r\n \r\n\t\treturn 0;\r\n\t }\r\n\t \r\n\tpublic static void main(String[] args){\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString s= scn.next();\r\n\t\tSystem.out.print(solution(s));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"pepcoding","sampleOutput":"1","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"e0c9a5f3-647b-4bbf-91d4-8ffeb0fda759","name":"First Non-repeating Character","slug":"first-non-repeating-character","type":1}],"next":{"id":"c1af2e97-6e0c-4064-ae0f-538c3072bb1a","name":"First Non-repeating Character MCQ","type":0,"slug":"first-non-repeating-character-mcq"},"prev":{"id":"adfae411-551d-4579-bb73-67a42e5a550e","name":"Subdomain Visit Count","type":3,"slug":"subdomain-visit-count"}}}`

# First Non-repeating Character

1. You are given a string. 2. You have to find the index of the first non-repeating character in the given string. 3. If no such character exists, print "-1".

`{"id":"2115ac03-916d-43c5-bef4-73deab646c27","name":"First Non-repeating Character","description":"1. You are given a string.\r\n2. You have to find the index of the first non-repeating character in the given string.\r\n3. If no such character exists, print \"-1\".","inputFormat":"A string","outputFormat":"A number representing the index of the first non-repeating character.","constraints":"1 &lt;= length of the string &lt;= 10^5","sampleCode":{"cpp":{"code":"#include <iostream>\r\n#include <vector>\r\nusing namespace std;\r\n\r\nint solution(string &s)\r\n{\r\n \r\n}\r\n\r\nint main()\r\n{\r\n string s;\r\n cin >> s;\r\n solution(s);\r\n return 0;\r\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static int solution(String s) {\r\n\t\t// write your code here\r\n \r\n\t\treturn 0;\r\n\t }\r\n\t \r\n\tpublic static void main(String[] args){\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString s= scn.next();\r\n\t\tSystem.out.print(solution(s));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"pepcoding","sampleOutput":"1","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"e0c9a5f3-647b-4bbf-91d4-8ffeb0fda759","name":"First Non-repeating Character","slug":"first-non-repeating-character","type":1}],"next":{"id":"c1af2e97-6e0c-4064-ae0f-538c3072bb1a","name":"First Non-repeating Character MCQ","type":0,"slug":"first-non-repeating-character-mcq"},"prev":{"id":"adfae411-551d-4579-bb73-67a42e5a550e","name":"Subdomain Visit Count","type":3,"slug":"subdomain-visit-count"}}}`

Editor

# First Non-repeating Character

easy

1. You are given a string. 2. You have to find the index of the first non-repeating character in the given string. 3. If no such character exists, print "-1".

## Constraints

1 <= length of the string <= 10^5

## Format

A string

### Output

A number representing the index of the first non-repeating character.

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}pepcoding`

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}1`

Discussions

Show Discussion

Related Resources