Data Source: https://www.tiobe.com/tiobe-index/
Preprocessing: Sublime + Python
Visualization: https://github.com/Jannchie/Historical-ranking-data-visualization-based-on-d3.js
February 19, 2026
Data Source: https://www.tiobe.com/tiobe-index/
Preprocessing: Sublime + Python
Visualization: https://github.com/Jannchie/Historical-ranking-data-visualization-based-on-d3.js
In LeetCode Store, there are some kinds of items to sell. Each item has a price.
However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.
You are given the each item’s price, a set of special offers, and the number we need to buy for each item. The job is to output the lowest price you have to pay for exactly certain items as given, where you could make optimal use of the special offers.
Each special offer is represented in the form of an array, the last number represents the price you need to pay for this special offer, other numbers represents how many specific items you could get if you buy this offer.
You could use any of special offers as many times as you want.
Example 1:
Input: [2,5], [[3,0,5],[1,2,10]], [3,2] Output: 14 Explanation: There are two kinds of items, A and B. Their prices are $2 and $5 respectively. In special offer 1, you can pay $5 for 3A and 0B In special offer 2, you can pay $10 for 1A and 2B. You need to buy 3A and 2B, so you may pay $10 for 1A and 2B (special offer #2), and $4 for 2A.
Example 2:
Input: [2,3,4], [[1,1,0,4],[2,2,1,9]], [1,2,1] Output: 11 Explanation: The price of A is $2, and $3 for B, $4 for C. You may pay $4 for 1A and 1B, and $9 for 2A ,2B and 1C. You need to buy 1A ,2B and 1C, so you may pay $4 for 1A and 1B (special offer #1), and $3 for 1B, $4 for 1C. You cannot add more items, though only $9 for 2A ,2B and 1C.
Note:
Try all combinations.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// Author: Huahua // Running time: 4 ms class Solution { public: int shoppingOffers(vector<int>& price, vector<vector<int>>& special, vector<int>& needs) { int with_offer = INT_MAX; for (const auto& offer : special) { vector<int> new_needs(needs); bool valid_offer = true; for (int i = 0; i < price.size(); ++i) if (!(valid_offer &= ((new_needs[i] -= offer[i]) >= 0))) break; if (!valid_offer) continue; with_offer = min(with_offer, shoppingOffers(price, special, new_needs) + offer.back()); } int without_offer = inner_product(begin(price), end(price), begin(needs), 0); return min(with_offer, without_offer); } }; |
Given a string representing an expression of fraction addition and subtraction, you need to return the calculation result in string format. The final result should be irreducible fraction. If your final result is an integer, say 2, you need to change it to the format of fraction that has denominator 1. So in this case, 2 should be converted to 2/1.
Example 1:
Input:"-1/2+1/2" Output: "0/1"
Example 2:
Input:"-1/2+1/2+1/3" Output: "1/3"
Example 3:
Input:"1/3-1/2" Output: "-1/6"
Example 4:
Input:"5/3+1/3" Output: "2/1"
Note:
'0' to '9', '/', '+' and '-'. So does the output.±numerator/denominator. If the first input fraction or the output is positive, then '+' will be omitted.a/b+c/d = (a*d + b * c) / (b * d)
Time complexity: O(n)
Space complexity: O(1)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Author: Huahua class Solution { public: string fractionAddition(string expression) { int a = 0; int b = 1; int c; int d; char slash; istringstream in(expression); while (in >> c >> slash >> d) { a = a * d + b * c; b *= d; int gcd = abs(__gcd(a, b)); a /= gcd; b /= gcd; } return to_string(a) + "/" + to_string(b); } }; |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
// Author: Huahua // Running time: 0 ms class Fraction { public: Fraction(int a, int b): a_(a), b_(b) {} Fraction& operator+=(const Fraction& f) { a_ = a_ * f.b_ + b_ * f.a_; b_ = b_ * f.b_; int d = abs(__gcd(a_, b_)); a_ /= d; b_ /= d; return *this; } string toString() { return to_string(a_) + "/" + to_string(b_); } private: int a_; // hold the sign, e.g. can be +-. int b_; // always > 0. }; class Solution { public: string fractionAddition(string expression) { Fraction f(0, 1); int a; int b; char op; istringstream in(expression); while (in >> a >> op >> b) f += Fraction(a, b); return f.toString(); } }; |
Given an array, rotate the array to the right by k steps, where k is non-negative.
Example 1:
Input: [1,2,3,4,5,6,7] and k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4]
Example 2:
Input:[-1,-100,3,99] and k = 2 Output: [3,99,-1,-100] Explanation: rotate 1 steps to the right: [99,-1,-100,3] rotate 2 steps to the right: [3,99,-1,-100]
Note:
If k >= n, rotating k times has the same effect as rotating k % n times.
[1,2,3,4,5,6,7], K = 3
[5,6,7,1,2,3,4]
We can simulate the rotation with three reverses.
Time complexity: O(n)
Space complexity: O(1) in-place
C++
|
1 2 3 4 5 6 7 8 9 10 11 |
class Solution { public: void rotate(vector<int>& nums, int k) { if (nums.empty()) return; k %= nums.size(); if (k == 0) return; reverse(begin(nums), end(nums)); reverse(begin(nums), begin(nums) + k); reverse(begin(nums) + k, end(nums)); } }; |
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.
Example 1:
Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac" Output: true
Example 2:
Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc" Output: false
Subproblems : whether s3[0:i+j] can be formed by interleaving s1[0:i] and s2[0:j].
Time complexity: O(mn)
Space complexity: O(mn)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Author: Huhaua // Running time: 0 ms class Solution { public: bool isInterleave(string s1, string s2, string s3) { int l1 = s1.length(); int l2 = s2.length(); int l3 = s3.length(); if (l1 + l2 != l3) return false; // dp[i][j]: whehter s3[0:i+j] is a interleva of s1[0:i] and s2[0:j] vector<vector<int>> dp(l1 + 1, vector<int>(l2 + 1)); dp[0][0] = true; for (int i = 0; i <= l1; ++i) for (int j = 0; j <= l2; ++j) { if (i > 0) dp[i][j] |= dp[i - 1][j] && s1[i - 1] == s3[i + j - 1]; if (j > 0) dp[i][j] |= dp[i][j - 1] && s2[j - 1] == s3[i + j - 1]; } return dp[l1][l2]; } }; |
Recursion + Memorization
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
// Author: Huahua // Running time: 0 ms class Solution { public: bool isInterleave(string s1, string s2, string s3) { m_ = vector<vector<int>>(s1.length() + 1, vector<int>(s2.length() + 1, INT_MIN)); return dp(s1, s1.length(), s2, s2.length(), s3, s3.length()); } private: // m_[i][j]: whehter s3[0:i+j] is a interleva of s1[0:i] and s2[0:j] vector<vector<int>> m_; bool dp(const string& s1, int l1, const string& s2, int l2, const string& s3, int l3) { if (l1 + l2 != l3) return false; if (l1 == 0 && l2 == 0) return true; if (m_[l1][l2] != INT_MIN) return m_[l1][l2]; if (l1 > 0 & s3[l3 - 1] == s1[l1 - 1] && dp(s1, l1 - 1, s2, l2, s3, l3 - 1) ||l2 > 0 & s3[l3 - 1] == s2[l2 - 1] && dp(s1, l1, s2, l2 - 1, s3, l3 - 1)) m_[l1][l2] = 1; else m_[l1][l2] = 0; return m_[l1][l2]; } }; |