Skip to content

Instantly share code, notes, and snippets.

@agaase
Created August 10, 2018 04:47
Show Gist options
  • Save agaase/5effac006265a9b949fe5e13d371db8e to your computer and use it in GitHub Desktop.
Save agaase/5effac006265a9b949fe5e13d371db8e to your computer and use it in GitHub Desktop.
// source https://jsbin.com
<!DOCTYPE html>
<html>
<head>
<script src="https://rawgit.com/mauriciosantos/Buckets-JS/master/dist/buckets.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
/*
var a = new buckets.LinkedList();
a.add(1,0);
a.add(2,0)
console.log(a.toArray());
var d = new buckets.MultiDictionary();
d.set("a", "aseem");
d.set("a", "aakash");
console.log(d.get("a"));
*/
var hasTwoDistinctChars = function(st) {
var unique = [];
for(i=0; i<st.length;i++) {
if(unique.indexOf(st[i]) == -1) {
unique.push(st[i]);
}
}
return unique.length == 2 ? true : false;
}
function checkString(st) {
if(hasTwoDistinctChars(st)) {
return st;
}
else if(st.length ==2) {
return false;
}
else {
const stt1 = checkString(st.substring(0,st.length-1));
const stt2 = checkString(st.substring(1,st.length));
return stt1.length > stt2.length ? stt1 : stt2;
}
}
console.log(checkString("ababcbcbaaabbdef"));
</script>
<script id="jsbin-source-javascript" type="text/javascript">/*
var a = new buckets.LinkedList();
a.add(1,0);
a.add(2,0)
console.log(a.toArray());
var d = new buckets.MultiDictionary();
d.set("a", "aseem");
d.set("a", "aakash");
console.log(d.get("a"));
*/
var hasTwoDistinctChars = function(st) {
var unique = [];
for(i=0; i<st.length;i++) {
if(unique.indexOf(st[i]) == -1) {
unique.push(st[i]);
}
}
return unique.length == 2 ? true : false;
}
function checkString(st) {
if(hasTwoDistinctChars(st)) {
return st;
}
else if(st.length ==2) {
return false;
}
else {
const stt1 = checkString(st.substring(0,st.length-1));
const stt2 = checkString(st.substring(1,st.length));
return stt1.length > stt2.length ? stt1 : stt2;
}
}
console.log(checkString("ababcbcbaaabbdef"));</script></body>
</html>
/*
var a = new buckets.LinkedList();
a.add(1,0);
a.add(2,0)
console.log(a.toArray());
var d = new buckets.MultiDictionary();
d.set("a", "aseem");
d.set("a", "aakash");
console.log(d.get("a"));
*/
var hasTwoDistinctChars = function(st) {
var unique = [];
for(i=0; i<st.length;i++) {
if(unique.indexOf(st[i]) == -1) {
unique.push(st[i]);
}
}
return unique.length == 2 ? true : false;
}
function checkString(st) {
if(hasTwoDistinctChars(st)) {
return st;
}
else if(st.length ==2) {
return false;
}
else {
const stt1 = checkString(st.substring(0,st.length-1));
const stt2 = checkString(st.substring(1,st.length));
return stt1.length > stt2.length ? stt1 : stt2;
}
}
console.log(checkString("ababcbcbaaabbdef"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment