A school is arranging students in a line for an annual photograph. The students are required to stand in a non-decreasing order of height. The expected order is represented by an array, where each element corresponds to the expected height of the student at that position. Given the current arrangement of the students’ heights, determine the number of positions where the height of the student does not match the expected height.
You are given a class with three methods: first(), second(), and third(). These methods are called concurrently by three threads. The goal is to ensure that second() is executed only after first() has been executed, and third() is executed only after second() has been executed. The execution of these methods is asynchronous, and you need to design a mechanism that guarantees the correct order of execution regardless of the operating system’s thread scheduling.
You are given two arrays: arr1 and arr2. The elements of arr2 are distinct, and all elements in arr2 exist in arr1. The task is to sort the elements of arr1 such that the relative ordering of elements in arr1 matches the order of elements in arr2. Elements in arr1 that are not present in arr2 should be placed at the end of arr1 in ascending order.
The Tribonacci sequence is defined by the following recurrence relation: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0. Given an integer n, return the value of Tn.
You are given an array of strings words and a string chars. A string is considered ‘good’ if it can be formed using characters from chars where each character can be used at most once. Your task is to return the sum of the lengths of all ‘good’ strings in words.