> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/05-23-2022-811.-subdomain-visit-count.md).

# 05/23/2022 811. Subdomain Visit Count

```
Set<Map.Entry<String,Integer>> s = m.entrySet();
for (Map.Entry<String, Integer> entry: s)
        {
            // Using the getKey to get key of the it element
            // Using the getValue to get value of the it element
            System.out.println("Before change of value = " + 
                       entry.getKey() + "   " +  entry.getValue())

```

```
// Some code
for(data-type variable : array | collection)
  {
   // Code to be executed
  }
```

Method:

For an address like `a.b.c`, we will count `a.b.c`, `b.c`, and `c`. For an address like `x.y`, we will count `x.y` and `y`.

To count these strings, we will use a hash map. To split the strings into the required pieces. First we use the split the string with space and get the value with the index 0. Then we scan the string at index 1 to find the character ".", When we found this character, we use the substring method to get the substring and put it and its frequency to the map.  Finally, we iterate the map.entryset() to add the values and keys to the results.

Time O(N)

Space O(N)
