Manafall Daily Quest

Subsequence Validator

Function Name: isValidSubsequence

Description

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'.

Requirements

  • The function must be named isValidSubsequence.
  • The function must take exactly two parameters: the first parameter is the original string (text), and the second parameter is the string to validate as subsequence (sequence).
  • The function must return a boolean value.
  • Empty string ('') should return true since it is a subsequence of any string.
  • The function should not use any built-in string comparison methods, instead, loop through the characters and validate manually.

Examples

Example 1: isValidSubsequence('abcde', 'ace') returns true.Example 2: isValidSubsequence('computer', 'core') returns false.Example 3: isValidSubsequence('sequence', 'sene') returns true.Example 4: isValidSubsequence('test', '') returns true.

Simple String Compression

Mon Aug 12 2024

You are tasked with writing a function that applies a basic form of string compression. The compression algorithm you should implement will take a string consisting solely of alphabetical characters and output a compressed version of the string. In the compressed version, sequences of repeated characters should be replaced by that character followed by an integer indicating how many times the character repeats consecutively. For instance, 'aaabcc' would be compressed to 'a3b1c2'. The function should only compress the string if it results in a smaller string than the input.

Prev Quest

File Path Simplifier

Wed Aug 14 2024

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.

Next Quest