Manafall Daily Quest

File Path Simplifier

Function Name: simplifyPath

Description

Write a function that simplifies an input string representing a file path.

For simplification, the function should follow these rules:

1. A double period '..' moves the directory up a level, while a single period '.' means the current directory and should be removed.

2. The return value should always begin with a slash '/', and there should be only one slash '/' separating each directory name. The last directory name (if it exists) should not end with a slash unless the path is just a root '/'.

3. The function should eliminate any multiple slashes '//' and return a canonical path.

4. Assume all input paths are non-empty strings.

Requirements

  • The functionName 'simplifyPath' must accept a single string parameter.
  • The function should normalize the path by applying the simplification rules above and return the simplified path as a string.
  • Do not use any built-in path normalization methods available in programming libraries; the goal is to implement the functionality from scratch.
  • The function should be able to handle relative and absolute paths.
  • Provide a solution that has O(n) time complexity, where n is the length of the input path.

Examples

Example Call: simplifyPath('/home/./x/../y/')Example Result: '/home/y'Example Call: simplifyPath('/a/../../../b/')Example Result: '/b'Example Call: simplifyPath('//multiple///slashes///')Example Result: '/multiple/slashes'

Links

https://en.wikipedia.org/wiki/Path_(computing)#Absolute_and_relative_pathshttps://leetcode.com/problems/simplify-path/

Subsequence Validator

Tue Aug 13 2024

Write a function that takes two strings as arguments and returns a boolean indicating whether the second string is a subsequence of the first one.A subsequence of a string is a new string generated from the original string with some characters(can be none) deleted without changing the relative order of the remaining characters.For example, 'ace' is a subsequence of 'abcde', but 'aec' is not. The function should be case-sensitive, meaning that 'ace' is not a subsequence of 'ABCDE'.

Prev Quest

Custom Sort String

Thu Aug 15 2024

You need to write a function, sortCharactersByOrder, which takes in two strings as parameters.The first string, 'order', represents the order of characters defined by the user.The second string, 'text', contains the text that needs to be sorted according to the order provided by the 'order' string.The function should return a new string in which the characters of 'text' are ordered based on the sequence of characters present in the 'order'.Characters in 'text' which are not present in 'order' should be appended to the end of the returned string, in the original order they appear in 'text'.If the 'order' string has characters not present in 'text', they should be ignored.The function should be case-sensitive, treating upper and lower case letters as different characters.

Next Quest