Загрузка...

Maximum Number of Words Found in Sentences | LeetCode Easy | String Logic | C++

🔹 Problem: Maximum Number of Words Found in Sentences (LeetCode)

In this video, we solve a beginner-friendly string observation problem.

The task is to find the maximum number of words present in a sentence.

---

🔹 Key Observation:

If words are separated by single spaces:

Words =
Spaces + 1

So instead of splitting strings,
we simply count spaces.

---

🔹 Approach:

For every sentence:
1. Count spaces
2. Add 1
3. Update maximum answer

---

🔹 Dry Run Example:

Sentence:
"alice and bob love leetcode"

Spaces:
4

Words:
5

Another sentence:
"this is great thanks very much"

Words:
6

Maximum Answer:
6

---

🔹 Time Complexity:
O(total characters)

🔹 Space Complexity:
O(1)

---

🔗 GitHub: https://github.com/DhruvOzha85
🔗 LeetCode Profile: https://leetcode.com/u/DhruvOzha/
🔗 LinkedIn: https://www.linkedin.com/in/dhruv-ozha-bb378639b/

---

📌 Notes:
- Great beginner string problem
- Important observation-based logic
- Efficient without split()

---

🔥 Follow for more daily DSA problem solutions!

#leetcode #strings #wordcount #dsa #codinginterview #cplusplus #programming #algorithms #coding #leetcodeeasy #tech #softwareengineer #placements #codingpractice

maximum number of words found in sentences, string problems, word counting, leetcode easy, dsa problems, coding interview questions, c++ dsa, algorithms, programming, interview prep, coding practice

Видео Maximum Number of Words Found in Sentences | LeetCode Easy | String Logic | C++ канала Dhruv Ozha
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять