You are given an array prices where prices[i] is the price of a given stock on the ith day.
Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times) with the following restrictions:
After you sell your stock, you cannot buy stock on the next day (i.e., cooldown one day).
Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
התהליך הוא ראיון אישי, עם כמה שאלות על עצמך, ואז שאלות יותר ומתמטיות וניהוליות. שני אנשים הם המראיינים
שאלות מתוך הראיון
אתה בקומה העליונה של הבניין ופורצת שריפה, ישנן שתי יציאות חירום, אחת למדרגות הארוכות ,והשנייה ליציאה למסדרון ראשי, אך היא רחוקה יותר, ויקח זמן להגיע עליה,מהיכן תבחר לצאת
We can determine how "out of order" an array A is by counting the number of inversions it has. Two elements A[i] and A[j] form an inversion if A[i] > A[j] but i < j. That is, a smaller element appears after a larger element.
Given an array, count the number of inversions it has. Do this faster than O(N^2) time.
You may assume each element in the array is distinct.
For example, a sorted list has zero inversions. The array [2, 4, 1, 3, 5] has three inversions: (2, 1), (4, 1), and (4, 3). The array [5, 4, 3, 2, 1] has ten inversions: every distinct pair forms an inversion.
תשובות
הוסף תשובה
|
לצפיה בתשובות
ספטמבר 2021
I have an O(NlogN) solution:
For each element, calculate the difference in position between the sorted (asc) and unsorted array. If an element "moved left" by x, add x to the counter.