[Fortinet] OA 2025 start – 9 Mar (generic)

How Many Words

    A sentence is made up of a group of words. Each word is a sequence of letters, ('a'-'z', 'A'-'Z'), that may contain one or more hyphens and may end in a punctuation mark: period (.), comma (,), question mark (?), or exclamation point (!). Words will be separated by one or more white space characters. Hyphens join two words into one and should be retained while the other punctuation marks should be stripped. Determine the number of words in a given sentence.

    Example

    s = "How many eggs are in a half-dozen, 13?"
    The list of words in the string is ['How', 'many', 'eggs', 'are', 'in', 'a', 'half-dozen'] and the number of words is 7. Notice that the numeric string, '13', is not a word because it is not within the allowed characters.

    Function Description

    Complete the function howMany in the editor below.

    howMany has the following parameter(s):
    sentence: a string

    Returns:
    int: an integer that represents the number of words in the string

    Constraints
    0 < length of s ≤ 10⁵


    Sort the Summary

      Given an array of integers, create a 2-dimensional array where the first element is a distinct value from the array and the second element is that value’s frequency within the array. Sort the resulting array descending by frequency. If multiple values have the same frequency, they should be sorted ascending.

      Example

      arr = [3, 3, 1, 2, 1]

      • There are two values, 3 and 1, each with a frequency of 2, and one value 2 with a frequency of 1: [[3, 2], [1, 2], [2, 1]]
      • Sort the 2-dimensional array descending by frequency: [[3, 2], [1, 2], [2, 1]]
      • Sort the 2-dimensional array ascending by value for values with the same frequency: [[1, 2], [3, 2], [2, 1]]

      Function Description

      Complete the function groupSort in the editor below.

      groupSort has the following parameter(s):
      int arr[n]: an array of integers

      Returns:
      int[n][2]: a 2-d array of integers sorted as described

      Constraints
      1 ≤ n ≤ 10⁵


      我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

      We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

      Leave a Reply

      Your email address will not be published. Required fields are marked *