Skip to main content

Command Palette

Search for a command to run...

Maximum Number of Words Found in Sentences

Published
1 min read
Maximum Number of Words Found in Sentences
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

A sentence is a list of words that are separated by a single space with no leading or trailing spaces.

You are given an array of strings sentences, where each sentences[i] represents a single sentence.

Return the maximum number of words that appear in a single sentence.

LeetCode Problem - 2114

class Solution {
    // Method to find the maximum number of words in a sentence
    public int mostWordsFound(String[] sentences) {
        // Initialize a variable to store the maximum number of words found
        int maxWords = 1;

        // Iterate through each sentence in the array
        for (int i = 0; i < sentences.length; i++){
            // Find the number of words in the current sentence
            int numOfWords = lengthOfSentence(sentences[i]);

            // Update the maximum number of words if the current sentence has more words
            if(numOfWords > maxWords){
                maxWords = numOfWords;
            }
        }
        // Return the maximum number of words found
        return maxWords;
    }

    // Method to find the number of words in a sentence
    public static int lengthOfSentence(String str){
        // Split the sentence into an array of words
        String[] arr = str.split(" ");

        // Get the length of the array, which represents the number of words in the sentence
        int length = arr.length;

        // Return the number of words in the sentence
        return length;
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.