Description

The prerequisite skill means a skill that is required to be learned prior to learning a certain skill.

For example, if the order of the prerequisite skill is Spark → Lightning bolt → Thunder, the Lightning bolt should be learned prior to learning Thunder, and Spark should be learned prior to learning Lightning bolt.

Other skills not listed in the above order (such as Healing) can be learned regardless of order. Therefore, skill tree such as Spark → Healing → Lightning bolt → Thunder is possible, but Lightning bolt → Spark → Healing → Thunder is impossible.

Given the order of prerequisite skill skill and an array skill_trees1 containing skill trees created by users are given as parameters, write a function solution to return the number of available skill trees.

Constraints
  • Skill is represented as the upper-case alphabet, and all strings consist of the upper-case alphabet only.
  • Order of skill and skill trees are represented as a string.
    • For example, C → B → D is presented by "CBD".
  • Length of skill, the order of prerequisite skill, is between 1 and 26, and there are no duplicated skills.
  • skill_trees is an array whose length is between 1 and 20.
  • Each element of skill_trees is a string of length between 2 and 26, and there are no duplicated skills.
Examples
skill skill_trees return
"CBD" ["BACDE", "CBADF", "AECB", "BDA"] 2
  • "BACDE": C skill should be learned prior to learning B skill. Hence this skill tree is impossible.
  • "CBADF": This is an available skill tree.
  • "AECB": This is an available skill tree.
  • "BDA": C skill should be learned prior to learning B skill. Hence this skill tree is impossible.

  1. Skill tree: The order where the user learns the skill. 

Result Stop
Result of [Run Test] or [Submit] will be displayed here
내가 제출한 코드가 왜 틀렸는지 프로그래머스 AI에게 물어보세요.
제출 후 채점하기를 눌러 30점 이상인 경우 물어볼 수 있어요.
베타 기간 동안에는 한 문제당 1번만 물어볼 수 있어요.