KatInterview

Filter Files Without Write Access

StringsAuto-graded · 14 test cases
MediumAuto-gradedStringsstring-parsingfilteringpermissions

Last updated

Tests string parsing and bitwise permission logic to identify files that lack write permissions across all user categories.

You receive a collection of file records where each record contains a permission string followed by a filename, separated by a space. The permission string follows the Unix convention with exactly 9 characters.

These 9 characters are organized into three groups of three:

  • Characters 0-2: owner permissions
  • Characters 3-5: group permissions
  • Characters 6-8: other users' permissions

Within each group, the positions represent:

  • Position 0 (of the group): read permission ('r' or '-')
  • Position 1 (of the group): write permission ('w' or '-')
  • Position 2 (of the group): execute permission ('x' or '-')

A hyphen ('-') indicates the absence of that permission.

Your task is to identify files where no one has write permission. This means the write permission character must be '-' for the owner (index 1), the group (index 4), and others (index 7).

Return the filenames of all such files in alphabetical order.

Constraints

  • The input list contains 1 to 1000 records
  • Each permission string is exactly 9 characters
  • Filenames contain only alphanumeric characters
  • Each record follows the format: "<9-char-permissions> <filename>"

Examples

Example 1

Input: filter_non_writable_files(['r-xr-x-x file1', 'rw-r--r-- file2', 'r--r--r-- file3'])

Output: ['file3']

Hints

Hint 1

The write permission appears at a fixed position within each of the three permission groups.

Hint 2

You only need to check three specific character positions in the permission string.

Hint 3

Don't forget to sort the results alphabetically before returning.