I was solving the problem :1732D1 - Balance (Easy version). And my solution was same as i keep the track of thekth-MEXof thexthelement when ever the request has been made. So for checking whether the kth element is present in the set or not, i usedunordered_map<>by while adding ...
stringkey; // each node stores a map to its child nodes unordered_map<char,Trie*>character; }; // Data structure to store a heap node structNode { stringkey; intcount; }; // Comparison object used to order the max-heap structcomp { booloperator()(constNode&lhs,constNode&rhs)const{...
[try Beta version] Not logged in registerlog infunction template <algorithm> std::find_iftemplate <class InputIterator, class UnaryPredicate> InputIterator find_if (InputIterator first, InputIterator last, UnaryPredicate pred); Find element in rangeReturns an iterator to the first element in the...
Your runtime complexity should be less than O(n2). There is only one duplicate number in the array, but it could be repeated more than once. Runtime: 28ms 1 class Solution { 2 public: 3 int findDuplicate(vector<int>& nums) { 4 if(nums.empty()) return 0; 5 6 unordered_map<int...
// string::find_first_of#include <iostream>// std::cout#include <string>// std::string#include <cstddef>// std::size_tintmain () { std::string str ("Please, replace the vowels in this sentence by asterisks."); std::size_t found = str.find_first_of("aeiou");while(found!=std...
unordered_map<int,int>table; vector<int>start_arr;for(inti =0; i < size; i++){ start_arr.push_back(intervals[i].start); table[intervals[i].start]=i; } sort(start_arr.begin(), start_arr.end()); vector<int> right_idx(size, -1);for(inti =0; i < size; i++){intidx =...
class Solution {public: vector> findDuplicate(vector& paths) { vector> res; unordered_map> m; for(string path:paths){ istringstream is(path); string pre="",t=""; is>>pre; while(is>>t){ int idx=t.find_last_of('('); string dir=pre+"/"+t.substr(0,idx); string content=t.su...
unordered_map<string, string> lookup; // Function to check if a cell (i, j) is valid or not bool isValid(int i, int j, int N) { return (i >= 0 && i < N && j >= 0 && j < N); } // Find the longest path starting from cell (i, j) formed by adjacent // numbers ...
// Running time: 80ms (beats 94.68%) class Solution { public: vector<vector<string>> findDuplicate(vector<string>& paths) { unordered_map<string, vector<string>> files; // content -> filenames for (const string& path : paths) { string folder; int i = 0; while (path[i] != ' ...
C++ Library - <unordered_map> C++ Library - <unordered_set> C++ Library - <vector> C++ Library - <algorithm> C++ Library - <iterator> The C++ Advanced Library C++ Library - <any> C++ Library - <barrier> C++ Library - <bit> C++ Library - <chrono> C++ Library - <cinttypes> C++ Libr...