[GSK] OA 2025 Start – 12 Feb (Generic)

Find School Count

Given the dataset of schools and the subjects they offer as a pandas dataframe, perform the following operations:

  • Drop all the schools offering fewer than 3 subjects.
  • Clean the state_code column such that it only contains alpha-numeric characters.
  • For each state, return the number of schools offering English, Maths, Physics and Chemistry, each in a separate column.

The given dataframe consists of three columns:

  • school_id - School ID for each student
  • state_code - Unique identifier for each state
  • subjects - space-separated strings of subjects, all in lowercase

Consider the following dataframe:

school_idstate_codesubjects
sch_1l@sc_1english maths chemistry
sch_2)}sc_2english physics chemistry
sch_3l@sc_2maths biology
sch_4sc_2_
sch_5sc_1#@social_studies maths literature
sch_6sc_10#@english maths history

Function Description

Complete the function schoolCount in the editor below.

schoolCount has the following parameter(s):

  • df: a pandas dataframe

Returns

  • pandas dataframe: the results of processing maintaining the original order that state codes are encountered

Constraints

  • 1 ≤ number of rows in df ≤ 1000

Analyzing Arrays

Consider a 1-based array of n integers, arr[n]. For each element arr[i] where 1 ≤ i ≤ n, determine the value of arr[i]^(arr[i+1]) modulo (10^9 + 7). Return the lowest index of the highest modulo value.

Example

arr = [3, 5, 4, 5, 2, 10]

index iarr[i]^(arr[i+1]) modulo (10^9 + 7)result
13^5 modulo (10^9 + 7)243
25^4 modulo (10^9 + 7)625
34^5 modulo (10^9 + 7)1024
45^2 modulo (10^9 + 7)25
52^10 modulo (10^9 + 7)1024

The greatest of these values is 1024 occurring at indices 3 and 5. Return the smaller index, 3.

Function Description

Complete the function powerArray in the editor.

powerArray has the following parameter:

  • int arr[n]: the integers to analyze

Returns:

  • int: the smallest index element that results in the highest value

Constraints

  • 1 ≤ n ≤ 10^5
  • 1 ≤ arr[i] ≤ 100

Parameters:

  • string s1: the first string, which always has a length of 3
  • string s2: the second string

Returns:

  • int: the number of times s1 appears as a subsequence in s2

Constraints:

  • length of s1 = 3
  • 1 ≤ length of s2 ≤ 5 * 10^5
  • s1 and s2 consist of uppercase English letters, A-Z

Leave a Reply

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