Day 84: Find Repeated Character From a String of 100DaysCodingChallenge

Hello all, 

#day84 

Day84 

Today's task was to Write a JavaScript program to find the Repeted Character in a given string. Words must be separated by only one space.

Example:
Sample Input: repeated
Sample Output: e


I have started the 100 days of coding challenge to improve my programming skills..

Code : 

// character that is repeated
function findRepeatFirstN2(s) {
  // This is O(N^2) method
  let p = -1, i, j;
  for (i = 0; i < s.length; i++) {
    for (j = i + 1; j < s.length; j++) {
      if (s[i] == s[j]) {
        p = i;
        break;
      }
    }
    if (p != -1)
      break;
  }
  return p;
}
// Driver code
//let str = "geeksforgeeks";
let str = prompt("Enter a String : ");
let pos = findRepeatFirstN2(str);
if (pos == -1)
  console.log("Not found");
else
  console.log(str[pos]);
// This code is contributed

Output :     

 




Happy Coding:)

Thank you...      

Comments

Popular posts from this blog

Day 55: Pattern using loops of 100DaysCodingChallenge

Day 7: Square or Power Integer Numbers of 100DaysCodingChallenge

Day 45: Pattern using loops of 100DaysCodingChallenge