Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h2>Hacker Rank Practice Test</h2>
<a href="https://www.hackerrank.com/challenges/special-palindrome-again">Medium Level - 58.99% pass rate</a>
</br>
</br>
<i>Started at 3:07 PM - HackerRank crashed at 3:45</i>
</br>
</br>
<div id="here"></div>
              
            
!

CSS

              
                
              
            
!

JS

              
                const print = msg => {
  console.log(msg)
  let el = document.getElementById("here")
  let n = document.createElement("div")
  n.innerHTML = msg
  el.appendChild(n)
}

const substrCount = (strLng, str) => {
  let found = str.split("")
  let last = ""

  for (let i = 0; i < strLng - 1; i++) {
    const current = str.charAt(i)
    const nxt = str.charAt(i + 1)

    // aa
    if (current === nxt) {
      found.push(current + nxt)
      last = current + nxt
      let innerlast = last

      //aaa, aaaa
      for (let j = i + 2; j < strLng; j++) {
        const nxtTwo = str.charAt(j)
        if (nxtTwo === str.charAt(j - 1)) {
          innerlast += nxtTwo
          found.push(innerlast)
        } else {
          const left = innerlast.length
          let valid = false
          //aabaa, aaabaaa
          for (let k = j + 1; k < j + 1 + left; k++) {
            if (innerlast.charAt(0) === str.charAt(k)) {
            } else break

            if (k === j + left) {
              innerlast += str.charAt(j) + innerlast
              valid = true
            }
          }
          if (valid) found.push(innerlast)
          break
        }
      }
    }

    //aba
    if (current === str.charAt(i + 2) && current !== str.charAt(i + 1)) {
      found.push(current + str.charAt(i + 1) + str.charAt(i + 2))
    }
  }

  print(found)
  return found.length
}

print(`aaaa ${substrCount(4, "aaaa")} expected 10`)
print(`ababa ${substrCount(5, "ababa")} expected 8`)
print(`ababcda ${substrCount(7, "ababcda")} expected 9`)
print(`aaaabaa ${substrCount(7, "aaaabaa")} expected 16`)
print(`bbaabaab ${substrCount(8, "bbaabaab")} expected 13`)
print(`aaabaaa ${substrCount(7, "aaabaaa")} expected 16`)
              
            
!
999px

Console