Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ Each problem follows this structure:

## Solutions

📊 **Statistics**: 52 problems solved (migrated to new structure)
📊 **Statistics**: 53 problems solved (migrated to new structure)

| Difficulty | Count |
|------------|-------|
| Easy | 36 |
| Easy | 37 |
| Medium | 15 |
| Hard | 1 |

Expand Down
3 changes: 2 additions & 1 deletion docs/EASY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Easy Problems

Total: 36 problems solved
Total: 37 problems solved

## Solutions

Expand Down Expand Up @@ -37,6 +37,7 @@ Total: 36 problems solved
| 2011 | [Final Value of Variable After Performing Operations](https://leetcode.com/problems/final-value-of-variable-after-performing-operations/) | [FinalValueOfVariableAfterPerformingOperations2011.java](../src/main/java/com/leetcode/easy/FinalValueOfVariableAfterPerformingOperations2011.java) | [FinalValueOfVariableAfterPerformingOperations2011Test.java](../src/test/java/com/leetcode/easy/FinalValueOfVariableAfterPerformingOperations2011Test.java) |
| 2032 | [Two Out of Three](https://leetcode.com/problems/two-out-of-three/) | [TwoOutOfThree2032.java](../src/main/java/com/leetcode/easy/TwoOutOfThree2032.java) | [TwoOutOfThree2032Test.java](../src/test/java/com/leetcode/easy/TwoOutOfThree2032Test.java) |
| 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs/) | [CheckIfAllAsAppearsBeforeAllBs2124.java](../src/main/java/com/leetcode/easy/CheckIfAllAsAppearsBeforeAllBs2124.java) | [CheckIfAllAsAppearsBeforeAllBs2124Test.java](../src/test/java/com/leetcode/easy/CheckIfAllAsAppearsBeforeAllBs2124Test.java) |
| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix/) | [CountingWordsWithAGivenPrefix2185.java](../src/main/java/com/leetcode/easy/CountingWordsWithAGivenPrefix2185.java) | [CountingWordsWithAGivenPrefix2185Test.java](../src/test/java/com/leetcode/easy/CountingWordsWithAGivenPrefix2185Test.java) |
| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks/) | [CountAsterisks2315.java](../src/main/java/com/leetcode/easy/CountAsterisks2315.java) | [CountAsterisks2315Test.java](../src/test/java/com/leetcode/easy/CountAsterisks2315Test.java) |
| 2469 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature/) | [ConvertTheTemperature2469.java](../src/main/java/com/leetcode/easy/ConvertTheTemperature2469.java) | [ConvertTheTemperature2469Test.java](../src/test/java/com/leetcode/easy/ConvertTheTemperature2469Test.java) |
| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target/) | [NumberOfEmployeesWhoMetTheTarget2798.java](../src/main/java/com/leetcode/easy/NumberOfEmployeesWhoMetTheTarget2798.java) | [NumberOfEmployeesWhoMetTheTarget2798Test.java](../src/test/java/com/leetcode/easy/NumberOfEmployeesWhoMetTheTarget2798Test.java) |
Expand Down
18 changes: 0 additions & 18 deletions src/CountingWordsWithAGivenPrefix2185.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Tags: Array, String
package com.leetcode.easy;

public class CountingWordsWithAGivenPrefix2185 {
/**
* Returns the number of strings in the array that have the given prefix.
*
* <p>This method iterates through each word in the array and checks if it starts
* with the specified prefix using String.startsWith().
*
* @param words the array of strings to search through
* @param pref the prefix string to match
* @return the count of words that start with the given prefix
*
* <p><b>Time Complexity:</b> O(n * m)
* <ul>
* <li>n = number of words in the array</li>
* <li>m = length of the prefix string</li>
* <li>We iterate through n words, and for each word, startsWith() compares up to m characters</li>
* </ul>
*
* <p><b>Space Complexity:</b> O(1)
* <ul>
* <li>Only uses a constant amount of extra space (the result counter variable)</li>
* <li>No data structures that scale with input size</li>
* </ul>
*/
public int prefixCount(String[] words, String pref) {
int res = 0;
for (String word : words) {
if (word.startsWith(pref)) {
res += 1;
}
}
return res;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.leetcode.easy;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class CountingWordsWithAGivenPrefix2185Test {
private CountingWordsWithAGivenPrefix2185 solution;

@BeforeEach
void setUp() {
solution = new CountingWordsWithAGivenPrefix2185();
}

@Test
void testPrefixCount_Example1_TwoMatches() {
// Input: words = ["pay","attention","practice","attend"], pref = "at"
// Output: 2
// Explanation: The 2 strings that contain "at" as a prefix are: "attention" and "attend".
String[] words = {"pay", "attention", "practice", "attend"};
String pref = "at";

int result = solution.prefixCount(words, pref);

assertEquals(2, result);
}

@Test
void testPrefixCount_Example2_NoMatches() {
// Input: words = ["leetcode","win","loops","success"], pref = "code"
// Output: 0
// Explanation: There are no strings that contain "code" as a prefix.
String[] words = {"leetcode", "win", "loops", "success"};
String pref = "code";

int result = solution.prefixCount(words, pref);

assertEquals(0, result);
}
}
Loading