Good questions
by rishul matta
JavaScript
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(S) {
// write your code in JavaScript (Node.js 8.9.4)
if (!S) {
return 0;
}
// 3 passes
var splitDot = S.split(".");
var splitDotQue = [];
splitDot.forEach((str) => splitDotQue = splitDotQue.concat(str.split("?")));
var finalSplit = [];
splitDotQue.forEach((str) => finalSplit = finalSplit.concat(str.split("!")));
// finalSplit has all the sentences!
var maxLength = 0;
finalSplit.forEach((sentence) => {
// you dont want to screw with trailing spaces multiple spaces
sentence = sentence.replace(/^\s+|\s+$/g, '');
sentence = sentence.replace(/\s+/g, " ");
// vaid word must contain atleast one alphabet
if (/[a-zA-Z]+/.test(sentence)) {
var nosOfWords = sentence.split(" ").length;
if (nosOfWords > maxLength) {
maxLength = nosOfWords;
}
}
});
return maxLength;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
/*
Hi, I hope you are seeing my solutions, most companies dont look at test code , if you took time to
check what I have done then I must say a Thank you.
*/
function solution(T) {
// write your code in JavaScript (Node.js 8.9.4)
var map = {};
var max = 0;
function calMax() {
if (Object.keys(map).length > max) {
max = Object.keys(map).length;
}
}
function add(x) {
if (!map[x]) {
map[x] = 1;
} else {
map[x] += 1;
}
}
function remove(x) {
map[x] -= 1;
if (map[x] <= 0) {
delete map[x];
}
}
function treeTraversal(node) {
if (!node) {
calMax();
return;
}
add(node.x);
treeTraversal(node.l);
...