Day - 96

Day - 96

Assalamu alaykum, everyone! It is the 96th day of my coding challenge! We passed 96 days ). It is a great result! I think we are going well! We have about 4 days!


Nowadays, I am thinking about another challenge that can be started after this one! But it could start later! Because I have deadlines for my projects these days! So, be patient till I start a new challenge!


Just, let me show today's challenge solution!


  1. Problem 2114. Maximum Number of Words Found in Sentences

Time Complexity:

The time complexity of this code is O(n^2) because there is a nested loop inside of the mostWordsFound function!

Space Complexity:

The space complexity of the code is O(1). This is because the code only uses a few variables, such as maxWords, count, and str. The values of these variables are not very large, so they do not take up a lot of space.

Code:

/*
?* @param {string[]} sentences
?* @return {number}
?*/

var mostWordsFound = function (sentences) {
? let maxWords = 0,
? ? count = 0;
? for (let i = 0; i < sentences.length; i++) {
? ? let str = sentences[i].trim();
? ? for (let j = 0; j < str.length; j++) {
? ? ? if (str[j] === " ") count++;
? ? }
? ? if (count + 1 > maxWords) maxWords = count + 1;
? ? count = 0;
? }
? return maxWords;
};        

2. Problem 2678. Number of Senior Citizens

Time Complexity:

The time complexity of the code is O(N), where N is the length of the input array. This is because the code iterates through each element in the input array, and the number of iterations is equal to the length of the array.

Space Complexity:

The space complexity of the code is O(1). This is because the code only uses a few variables, such as details and psg. The values of these variables are not very large, so they do not take up a lot of space.

Code:

/*
?* @param {string[]} details
?* @return {number}
?*/

var countSeniors = function (details) {
? return details.filter((psg) => +psg.slice(11, 13) > 60).length;
};        


#code #leetcode #javascript #typescript #react #coding #challenges #100daysofcodechallenge #problems #solutions

要查看或添加评论,请登录

社区洞察

其他会员也浏览了