//Covered queries
typeof typeof 1
cursor
3 larget number without sorting
//How idexes are store internally string and number value
//How to get 10 million data form mongodb without limit and skip
//let s= "abcabcbb";//Output should be 3 abc
// console.log('1')
// function demoFunction() {
// setTimeout(() => {
// console.log('2')
// }, 0)
// }
// const promise = new Promise((resolve, reject) => {
// console.log('3')
// resolve('promise result')
// })
// demoFunction()
// promise.then(() => {
// console.log('4')
// })
// console.log('5');
//1
//3
//5
//4
//2
// Input: s = "abcabcbb"
// Output: 3
function lengthOfLongestSubstring(s) {
let maxLength = 0;
let start = 0;
const charIndexMap = new Map(); // Map to store the index of each character
for (let end = 0; end < s.length; end++) {
const char = s[end];
if (charIndexMap.has(char)) {
// If the current character is already in the substring, update the start index
start = Math.max(start, charIndexMap.get(char) + 1);
}
// Update the length of the current substring
maxLength = Math.max(maxLength, end - start + 1);
// Update the index of the current character in the map
charIndexMap.set(char, end);
}
return maxLength;
}
// Example usage:
const s = "abcabcbb";
console.log(lengthOfLongestSubstring(s)); // Output: 3
Types of errorimperative vs declarative
uses of http interceptors use cases
Comments
Post a Comment