0% found this document useful (0 votes)
70 views3 pages

Hash Agile Technologies

Uploaded by

hemnathajay51
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views3 pages

Hash Agile Technologies

Uploaded by

hemnathajay51
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PROBLEM STATEMENT:

Find the First Non-Repeating Character

Write a program to find the first non-repeating character in a string. For input "swiss", the output

should be "w". You cannot use any built-in string or character frequency counting functions.

PROGRAM CODE:

function firstNonRepeatingChar(s: string): string | null {

const charCount: { [key: string]: number } = {};

for (let i = 0; i < s.length; i++) {

const char = s[i];

if (charCount[char]) {

charCount[char]++;

} else {

charCount[char] = 1;

for (let i = 0; i < s.length; i++) {

const char = s[i];

if (charCount[char] === 1) {

return char;

return null;
const inputString = "rummy";

const result = firstNonRepeatingChar(inputString);

console.log(result);

SAMPLE OUTPUTS:

You might also like