Qn 1 sum of digits until single digit https://leetcode.com/problems/add-digits/ * worked for all cases.. completed within 10 mins ``` /** * @param {number} num * @return {number} */ var addDigits = function(num) { while(num >= 10){ num = num.toString().split('').reduce((sum, digit) => sum + parseInt(digit, 10), 0) } return num }; ``` Qn 2 pattern string matching https://leetcode.com/problems/word-pattern/ * code is fine, but not able to debug why its not working for simple cases * took more than 15 mins ``` /** * @param {string} pattern * @param {string} s * @return {boolean} */ var wordPattern = function(pattern, s) { const words = s.split(' ') if(pattern.length !== words.length){ return false } let patternObj = {} console.log('lenght', pattern.length) for(let i =0; i < pattern.length; i++){ console.log('char', pattern[i]) if(!patternObj[pattern[i]]){ console.log(patternObj[pattern[i]], patternObj) patternObj[pattern[i]]= words[i] } else { console.log('words', words[i], pattern[i]) if(patternObj[words[i]] !== pattern[i]){ return false } } } console.log('finish') return true console.log(patternObj) // const patternMap = new Map() // const wordMap = new Map() // for(let i = 0; i < pattern.length; i++){ // const char = pattern[i] // const word = words[i] // if(!patternMap.has(char)){ // patternMap.set(char, word) // } // else if(patterMap.get(char) !== wsord){ // return false; // } // if(!wordMap.has(word)){ // wordMap.set(word, char) // } else { // if(wordMap.get(word) !== char){ // return false; // } // } // } // return true }; ``` Qn 3 database design for restaurant table reservation system * direction is correct * have some experience * ok ok with this ``` /** table reservation system ram resto 1 10 mohan 1 rams restorant : { id: name: address; o } seats booked: true; restorantId: 1 noOfeats: 10 serialNo. users: { userName: } orders :{ id: user: 12, restroantId: tableNo. status } { userId: 'mohane', restId: 1, tableNo.: 1, status: checked } */ ```