He tested on the sample:
[ERROR] Connection timeout
[INFO] User login
[ERROR] Disk timeout error
[WARNING] Low memory
[ERROR] timeout in module X
His command returned 3 (lines 1, 3, 5). The expected output was 3. It passed. powershell 3 cmdlets hackerrank solution
$map = @{}
$arr | ForEach-Object $map[$_] = $true
$s = @($input)[0]
$count = 1 + (($s -split '(?=[A-Z])') | Where-Object $_ -ne '' ).Count - 1
Write-Output $count
Better without double counting:
$s = @($input)[0]
$words = $s -split '(?=[A-Z])'
Write-Output $words.Count
Key trick: Regex split with lookahead.
The challenge will silently test you on: He tested on the sample: [ERROR] Connection timeout
$result = $data | Where-Object $_ -gt 0 | Measure-Object | Select-Object -ExpandProperty Count His command returned 3 (lines 1, 3, 5)
| Task | Cmdlets Used |
|------|----------------|
| Filter users by group | Get-ADUser, Where-Object |
| Sort files by size | Get-ChildItem, Sort-Object -Property Length |
| Select first N objects | Select-Object -First N |
| Output only specific columns | Select-Object Property1, Property2 |
| Convert to MB/GB | Calculated property with division |
| Skip header in CSV | Import-Csv, Select-Object -Skip 1 |