Feature Extraction
sentence-transformers
Safetensors
English
roberta
sentence-similarity
dense
Generated from Trainer
dataset_size:4088
loss:CoSENTLoss
Eval Results (legacy)
text-embeddings-inference
Instructions to use Sid-the-sloth/leetcode_unixcoder_final with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use Sid-the-sloth/leetcode_unixcoder_final with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("Sid-the-sloth/leetcode_unixcoder_final") sentences = [ "Name: Split BST | Code: // Time: O(n)\n// Space: O(h)\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n vector<TreeNode*> splitBST(TreeNode* root, int V) {\n if (!root) {\n return {nullptr, nullptr};\n } else if (root->val <= V) {\n const auto& result = splitBST(root->right, V);\n root->right = result[0];\n return {root, result[1]};\n } else {\n const auto& result = splitBST(root->left, V);\n root->left = result[1];\n return {result[0], root};\n }\n }\n};\n | Tags: Binary Search Tree,Binary Tree,Recursion,Tree", "Name: Parallel Courses III | Code: // Time: O(|V| + |E|)\n// Space: O(|E|)\n\nclass Solution {\npublic:\n int minimumTime(int n, vector<vector<int>>& relations, vector<int>& time) {\n vector<vector<int>> adj(n);\n vector<int> in_degree(n);\n for (const auto& relation : relations) {\n adj[relation[0] - 1].emplace_back(relation[1] - 1);\n ++in_degree[relation[1] - 1];\n }\n vector<int> q;\n vector<int> dist(n);\n for (int u = 0; u < n; ++u) {\n if (in_degree[u]) {\n continue;\n }\n q.emplace_back(u);\n dist[u] = time[u];\n }\n while (!empty(q)) {\n vector<int> new_q;\n for (const auto& u : q) {\n for (const auto& v : adj[u]) {\n dist[v] = max(dist[v], dist[u] + time[v]);\n --in_degree[v];\n if (!in_degree[v]) {\n new_q.emplace_back(v);\n }\n }\n }\n q = move(new_q);\n }\n return *max_element(cbegin(dist), cend(dist));\n }\n};\n | Tags: Array,Dynamic Programming,Graph,Topological Sort", "Name: Determine Whether Matrix Can Be Obtained By Rotation | Code: // Time: O(m * n)\n// Space: O(1)\n\nclass Solution {\npublic:\n bool findRotation(vector<vector<int>>& mat, vector<vector<int>>& target) {\n vector<function<bool (int, int)>> checks = {\n [&mat, &target](int i, int j) { return mat[i][j] == target[i][j]; },\n [&mat, &target](int i, int j) { return mat[i][j] == target[j][size(mat) - 1 - i]; },\n [&mat, &target](int i, int j) { return mat[i][j] == target[size(mat) - 1 - i][size(mat[0]) - 1 - j]; },\n [&mat, &target](int i, int j) { return mat[i][j] == target[size(mat[0]) - 1 - j][i]; },\n };\n const auto& traverse = [&mat, &target](const auto& check) {\n for (int i = 0; i < size(mat); ++i) {\n for (int j = 0; j < size(mat[0]); ++j) {\n if (!check(i, j)) {\n return false;\n }\n }\n }\n return true;\n };\n for (const auto& check : checks) {\n if (traverse(check)) {\n return true;\n }\n }\n return false;\n }\n};\n | Tags: Array,Matrix", "Name: Maximum Total Reward Using Operations I | Code: // Time: O(nlogn + r^2), r = max(rewardValues)\n// Space: O(r)\n\n// sort, dp, bitset\nclass Solution {\npublic:\n int maxTotalReward(vector<int>& rewardValues) {\n static const int MAX_VALUE = 20000;\n\n unordered_set<int> v_set(cbegin(rewardValues), cend(rewardValues));\n vector<int> sorted_v(cbegin(v_set), cend(v_set));\n sort(begin(sorted_v), end(sorted_v));\n bitset<(MAX_VALUE - 1) + 1> dp, mask;\n dp[0] = true;\n int i = 0;\n for (int i = 0, j = 0; i + 1 < size(sorted_v); ++i) {\n while (j < sorted_v[i]) {\n mask[j++] = true;\n }\n dp |= (dp & mask) << sorted_v[i];\n }\n int result = sorted_v.back() - 1;\n for (; !dp[result]; --result);\n return sorted_v.back() + result;\n }\n};\n\n// Time: O(nlogn + r^2), r = max(rewardValues)\n// Space: O(r)\n// sort, dp, bitset\nclass Solution2 {\npublic:\n int maxTotalReward(vector<int>& rewardValues) {\n static const int MAX_VALUE = 20000;\n\n unordered_set<int> v_set(cbegin(rewardValues), cend(rewardValues));\n vector<int> sorted_v(cbegin(v_set), cend(v_set));\n sort(begin(sorted_v), end(sorted_v));\n bitset<(MAX_VALUE * 2 - 1) + 1> dp, mask;\n dp[0] = true;\n int i = 0;\n for (int i = 0, j = 0; i < size(sorted_v); ++i) {\n while (j < sorted_v[i]) {\n mask[j++] = true;\n }\n dp |= (dp & mask) << sorted_v[i];\n }\n int result = 2 * sorted_v.back() - 1;\n for (; !dp[result]; --result);\n return result;\n }\n};\n\n// Time: O(nlogn + r^2), r = max(rewardValues)\n// Space: O(r)\n// sort, dp\nclass Solution3 {\npublic:\n int maxTotalReward(vector<int>& rewardValues) {\n unordered_set<int> v_set(cbegin(rewardValues), cend(rewardValues));\n vector<int> sorted_v(cbegin(v_set), cend(v_set));\n sort(begin(sorted_v), end(sorted_v));\n const int mx = sorted_v.back();\n vector<bool> dp((mx - 1) + 1);\n dp[0] = true;\n for (int i = 0; i + 1 < size(sorted_v); ++i) {\n for (int x = 0; x < min(sorted_v[i], mx - sorted_v[i]); ++x) {\n if (dp[x]) {\n dp[sorted_v[i] + x] = dp[x];\n }\n }\n }\n int result = mx - 1;\n for (; !dp[result]; --result);\n return mx + result;\n }\n};\n\n// Time: O(nlogn + r^2), r = max(rewardValues)\n// Space: O(r)\n// sort, dp\nclass Solution4 {\npublic:\n int maxTotalReward(vector<int>& rewardValues) {\n unordered_set<int> v_set(cbegin(rewardValues), cend(rewardValues));\n vector<int> sorted_v(cbegin(v_set), cend(v_set));\n sort(begin(sorted_v), end(sorted_v));\n const int mx = sorted_v.back();\n vector<bool> dp((mx * 2 - 1) + 1);\n dp[0] = true;\n for (int i = 0; i < size(sorted_v); ++i) {\n for (int x = 0; x < sorted_v[i]; ++x) {\n if (dp[x]) {\n dp[sorted_v[i] + x] = dp[x];\n }\n }\n }\n int result = 2 * mx - 1;\n for (; !dp[result]; --result);\n return result;\n }\n};\n | Tags: Array,Dynamic Programming" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
Gated model You can list files but not access them
Preview of files found in this repository