Issue regarding one of the Mountblue Job Challenges

I’m doing a challenge regarding the Super Reduced String challenge and I’ve come up with a code which is being acceptable for most of the cases except for 4 to 5 cases. I can’t think of any changes which I’ve to make or any other cases for which my code should be failed plz help me with my code

here’s the code

function superReducedString(s) {
    // Write your code here
  let str = s.split("")
  let newStr = []; let newStrng
  for(let  i=0; i<str.length; i++){
    let ele = str[i]; let c = 0;
    for(let j=0; j<str.length; j++){
        if(ele==str[j])
        c++
    }
    if(newStr.indexOf(ele)==-1){
      if(c%2!=0)
      newStr.push(ele)
    }
  }
  
  str = newStr.join("").toLowerCase()
  if(str==""){
  str = "Empty String"
  }
  return str
}

This is the challenge which I’m doing

try to reload it. It may open and I’ve written the code on my own and it seems to be working fine but can’t figure out why it is not accepting my code for some cases

function superReducedString(s) {
// Write your code here
let str = s.split(“”)
let newStr = ; let newStrng
for(let i=0; i<str.length; i++){
let ele = str[i]; let c = 0;
for(let j=0; j<str.length; j++){
if(ele==str[j])
c++
}
if(newStr.indexOf(ele)==-1){
if(c%2!=0)
newStr.push(ele)
}
}

str = newStr.join(“”).toLowerCase()
if(str==“”){
str = “Empty String”
}
return str
}

well actually that is the problem I can only see the arguments for case 0 , case 1 & case 2. it is not letting me show the arguments for other cases

Please don’t post literal pictures of your computer. Those are extremely difficult to read.

actually I have initialized newStr as a blank array, yeah I thought maybe I’d have to use a new variable to store my string so declared it as newString but it was not needed so I did not use it further ahead.

well I tried to share links but it was not loading , so I had to post pictures

Don’t post pictures of a computer. Those are nearly unreadable. At worst, copy-paste.

arguments for test case 0 is ‘aaabccddd’, for test case 1 it is ‘aa’, for test case2 it is ‘baab’

Stop posting pictures of your computer. Please copy-paste the code so it can be readable.

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

function superReducedString(s) {
    // Write your code here
  let str = s.split("")
  let newStr = [];
  for(let  i=0; i<str.length; i++){
    let ele = str[i]; let c = 0;
    for(let j=0; j<str.length; j++){
        if(ele==str[j])
        c++
    }
    if(newStr.indexOf(ele)==-1){
      if(c%2!=0)
      newStr.push(ele)
    }
  }
  
  str = newStr.join("").toLowerCase()
  if(str==""){
  str = "Empty String"
  }
  return str
}

1 Like

if we pass on the string ‘aaabbbcccddd’ it should eliminate all the possible pairs of characters leaving ‘abcd’

if you want to know more plz go through this link
: Programming problems and Competitions :: HackerRank

then enter contest and on the first page 8th challenge Super Reduced Challenge

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.