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**: 53 problems solved (migrated to new structure)
📊 **Statistics**: 54 problems solved (migrated to new structure)

| Difficulty | Count |
|------------|-------|
| Easy | 37 |
| Easy | 38 |
| 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: 37 problems solved
Total: 38 problems solved

## Solutions

Expand Down Expand Up @@ -34,6 +34,7 @@ Total: 37 problems solved
| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth/) | [RichestCustomerWealth1672.java](../src/main/java/com/leetcode/easy/RichestCustomerWealth1672.java) | [RichestCustomerWealth1672Test.java](../src/test/java/com/leetcode/easy/RichestCustomerWealth1672Test.java) |
| 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule/) | [CountItemsMatchingARule1773.java](../src/main/java/com/leetcode/easy/CountItemsMatchingARule1773.java) | [CountItemsMatchingARule1773Test.java](../src/test/java/com/leetcode/easy/CountItemsMatchingARule1773Test.java) |
| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence/) | [TruncateSentence1816.java](../src/main/java/com/leetcode/easy/TruncateSentence1816.java) | [TruncateSentence1816Test.java](../src/test/java/com/leetcode/easy/TruncateSentence1816Test.java) |
| 1941 | [Check if All Characters Have Equal Number of Occurrences](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/) | [CheckIfAllCharactersHaveEqualNumberOfOccurrences1941.java](../src/main/java/com/leetcode/easy/CheckIfAllCharactersHaveEqualNumberOfOccurrences1941.java) | [CheckIfAllCharactersHaveEqualNumberOfOccurrences1941Test.java](../src/test/java/com/leetcode/easy/CheckIfAllCharactersHaveEqualNumberOfOccurrences1941Test.java) |
| 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) |
Expand Down
16 changes: 0 additions & 16 deletions src/CheckIfAllCharactersHaveEqualNumberOfOccurrences1941.java

This file was deleted.

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

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

public class CheckIfAllCharactersHaveEqualNumberOfOccurrences1941 {
/**
* Checks if all characters in the string have equal number of occurrences.
*
* <p>Approach:
* <ul>
* <li>Use HashMap to count frequency of each character</li>
* <li>Put all frequency values into HashSet</li>
* <li>If HashSet size is 1, all characters have same occurrence count</li>
* </ul>
*
* <p>Time Complexity: O(n) where n is the length of the string, single pass required
* <p>Space Complexity: O(1) as at most 26 unique characters are stored (constraint: lowercase letters only)
*
* @param s input string containing only lowercase English letters
* @return true if all characters appear the same number of times, false otherwise
*/
public boolean areOccurrencesEqual(String s) {
Map<Character, Integer> freq = new HashMap<>();
for (char c : s.toCharArray()) {
freq.put(c, freq.getOrDefault(c, 0) + 1);
}
return new HashSet<>(freq.values()).size() == 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.leetcode.easy;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class CheckIfAllCharactersHaveEqualNumberOfOccurrences1941Test {

@Test
void testAreOccurrencesEqualExample1() {
CheckIfAllCharactersHaveEqualNumberOfOccurrences1941 solution = new CheckIfAllCharactersHaveEqualNumberOfOccurrences1941();
String s = "abacbc";
boolean result = solution.areOccurrencesEqual(s);
assertTrue(result, "The characters 'a', 'b', and 'c' should all occur 2 times in s");
}

@Test
void testAreOccurrencesEqualExample2() {
CheckIfAllCharactersHaveEqualNumberOfOccurrences1941 solution = new CheckIfAllCharactersHaveEqualNumberOfOccurrences1941();
String s = "aaabb";
boolean result = solution.areOccurrencesEqual(s);
assertFalse(result, "'a' occurs 3 times while 'b' occurs 2 times, which is not equal");
}
}
Loading