"content":"<p>Asocialmediacompanyistryingtomonitoractivityontheirsitebyanalyzingthenumberoftweetsthatoccurinselectperiodsoftime.Theseperiodscanbepartitionedintosmaller<strong>timechunks</strong>basedonacertainfrequency(every<strong>minute</strong>,<strong>hour</strong>,or<strong>day</strong>).</p>\n\n<p>Forexample,theperiod<code>[10,10000]</code>(in<strong>seconds</strong>)wouldbepartitionedintothefollowing<strong>timechunks</strong>withthesefrequencies:</p>\n\n<ul>\n\t<li>Every<strong>minute</strong>(60-secondchunks):<code>[10,69]</code>,<code>[70,129]</code>,<code>[130,189]</code>,<code>...</code>,<code>[9970,10000]</code></li>\n\t<li>Every<strong>hour</strong>(3600-secondchunks):<code>[10,3609]</code>,<code>[3610,7209]</code>,<code>[7210,10000]</code></li>\n\t<li>Every<strong>day</strong>(86400-secondchunks):<code>[10,10000]</code></li>\n</ul>\n\n<p>Noticethatthelastchunkmaybeshorterthanthespecifiedfrequency'schunksizeandwillalwaysendwiththeendtimeoftheperiod(<code>10000</code>intheaboveexample).</p>\n\n<p>DesignandimplementanAPItohelpthecompanywiththeiranalysis.</p>\n\n<p>Implementthe<code>TweetCounts</code>class:</p>\n\n<ul>\n\t<li><code>TweetCounts()</code>Initializesthe<code>TweetCounts</code>object.</li>\n\t<li><code>voidrecordTweet(StringtweetName,inttime)</code>Storesthe<code>tweetName</code>attherecorded<code>time</code>(in<strong>seconds</strong>).</li>\n\t<li><code>List<Integer>getTweetCountsPerFrequency(Stringfreq,StringtweetName,intstartTime,intendTime)</code>Returnsalistofintegersrepresentingthenumberoftweetswith<code>tweetName</code>ineach<strong>timechunk</strong>forthegivenperiodoftime<code>[startTime,endTime]</code>(in<strong>seconds</strong>)andfrequency<code>freq</code>.\n\t<ul>\n\t\t<li><code>freq</code>isoneof<code>"minute"</code>,<code>"hour"</code>,or<code>"day"</code>representingafrequencyofevery<strong>minute</strong>,<strong>hour</strong>,or<strong>day</strong>respectively.</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p> </p>\n<p><strong>Example:</strong></p>\n\n<pre>\n<strong>Input</strong>\n["TweetCounts","recordTweet","recordTweet","recordTweet","getTweetCountsPerFrequency","getTweetCountsPerFrequency","recordTweet","getTweetCountsPerFrequency"]\n[[],["tweet3",0],["tweet3",60],["tweet3",10],["minute","tweet3",0,59],["minute","tweet3",0,60],["tweet3",120],["hour","tweet3",0,210]]\n\n<strong>Output</strong>\n[null,null,null,null,[2],[2,1],null,[4]]\n\n<strong>Explanation</strong>\nTweetCountstweetCounts=newTweetCounts();\ntweetCounts.recordTweet("tweet3",0);// New tweet "tweet3" at time 0\ntweetCounts.recordTweet("tweet3", 60); // New tweet "tweet3" at time 60\ntweetCounts.recordTweet("tweet3", 10); // New tweet "tweet3" at time 10\ntweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 59); // return [2]; chunk [0,59] had 2 tweets\ntweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 60); // return [2,1]; chunk [0,59] had 2 tweets, chunk [60,60] had 1 tweet\ntweetCounts.recordTweet("tweet3", 120); // New tweet "tweet3" at time 120\ntweetCounts.getTweetCountsPerFrequency("hour", "tweet3", 0, 210); // return [4]; chunk [0,210] had 4 tweets\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= time, startTime, endTime <= 10<sup>9</sup></code></li>\n\t<li><code>0 <= endTime - startTime <= 10<sup>4</sup></code></li>\n\t<li>There will be at most <code>10<sup>4</sup></
"code":"class TweetCounts {\npublic:\n TweetCounts() {\n \n }\n \n void recordTweet(string tweetName, int time) {\n \n }\n \n vector<int> getTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime) {\n \n }\n};\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts* obj = new TweetCounts();\n * obj->recordTweet(tweetName,time);\n * vector<int> param_2 = obj->getTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */",
"__typename":"CodeSnippetNode"
},
{
"lang":"Java",
"langSlug":"java",
"code":"class TweetCounts {\n\n public TweetCounts() {\n \n }\n \n public void recordTweet(String tweetName, int time) {\n \n }\n \n public List<Integer> getTweetCountsPerFrequency(String freq, String tweetName, int startTime, int endTime) {\n \n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts obj = new TweetCounts();\n * obj.recordTweet(tweetName,time);\n * List<Integer> param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */",
"__typename":"CodeSnippetNode"
},
{
"lang":"Python",
"langSlug":"python",
"code":"class TweetCounts(object):\n\n def __init__(self):\n \n\n def recordTweet(self, tweetName, time):\n \"\"\"\n :type tweetName: str\n :type time: int\n :rtype: None\n \"\"\"\n \n\n def getTweetCountsPerFrequency(self, freq, tweetName, startTime, endTime):\n \"\"\"\n :type freq: str\n :type tweetName: str\n :type startTime: int\n :type endTime: int\n :rtype: List[int]\n \"\"\"\n \n\n\n# Your TweetCounts object will be instantiated and called as such:\n# obj = TweetCounts()\n# obj.recordTweet(tweetName,time)\n# param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)",
"__typename":"CodeSnippetNode"
},
{
"lang":"Python3",
"langSlug":"python3",
"code":"class TweetCounts:\n\n def __init__(self):\n \n\n def recordTweet(self, tweetName: str, time: int) -> None:\n \n\n def getTweetCountsPerFrequency(self, freq: str, tweetName: str, startTime: int, endTime: int) -> List[int]:\n \n\n\n# Your TweetCounts object will be instantiated and called as such:\n# obj = TweetCounts()\n# obj.recordTweet(tweetName,time)\n# param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)",
"__typename":"CodeSnippetNode"
},
{
"lang":"C",
"langSlug":"c",
"code":"\n\n\ntypedef struct {\n \n} TweetCounts;\n\n\nTweetCounts* tweetCountsCreate() {\n \n}\n\nvoid tweetCountsRecordTweet(TweetCounts* obj, char * tweetName, int time) {\n \n}\n\nint* tweetCountsGetTweetCountsPerFrequency(TweetCounts* obj, char * freq, char * tweetName, int startTime, int endTime, int* retSize) {\n \n}\n\nvoid tweetCountsFree(TweetCounts* obj) {\n \n}\n\n/**\n * Your TweetCounts struct will be instantiated and called as such:\n * TweetCounts* obj = tweetCountsCreate();\n * tweetCountsRecordTweet(obj, tweetName, time);\n \n * int* param_2 = tweetCountsGetTweetCountsPerFrequency(obj, freq, tweetName, startTime, endTime, retSize);\n \n * tweetCountsFree(obj);\n*/",
"__typename":"CodeSnippetNode"
},
{
"lang":"C#",
"langSlug":"csharp",
"code":"public class TweetCounts {\n\n public TweetCounts() {\n \n }\n \n public void RecordTweet(string tweetName, int time) {\n \n }\n \n public IList<int> GetTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime) {\n \n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts obj = new TweetCounts();\n * obj.RecordTweet(tweetName,time);\n * IList<int> param_2 = obj.GetTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */",
"__typename":"CodeSnippetNode"
},
{
"lang":"JavaScript",
"langSlug":"javascript",
"code":"\nvar TweetCounts = function() {\n \n};\n\n/** \n * @param {string} tweetName \n * @param {number} time\n * @return {void}\n */\nTweetCounts.prototype.recordTweet = function(tweetName, time) {\n \n};\n\n/** \n * @param {string} freq \n * @param {string} tweetName \n * @param {number} startTime \n * @param {number} endTime\n * @return {number[]}\n */\nTweetCounts.prototype.getTweetCountsPerFrequency = function(freq, tweetName, startTime, endTime) {\n \n};\n\n/** \n * Your TweetCounts object will be instantiated and called as such:\n * var obj = new TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */",
"code":"\nclass TweetCounts {\n\n init() {\n \n }\n \n func recordTweet(_ tweetName: String, _ time: Int) {\n \n }\n \n func getTweetCountsPerFrequency(_ freq: String, _ tweetName: String, _ startTime: Int, _ endTime: Int) -> [Int] {\n \n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * let obj = TweetCounts()\n * obj.recordTweet(tweetName, time)\n * let ret_2: [Int] = obj.getTweetCountsPerFrequency(freq, tweetName, startTime, endTime)\n */",
"__typename":"CodeSnippetNode"
},
{
"lang":"Go",
"langSlug":"golang",
"code":"type TweetCounts struct {\n \n}\n\n\nfunc Constructor() TweetCounts {\n \n}\n\n\nfunc (this *TweetCounts) RecordTweet(tweetName string, time int) {\n \n}\n\n\nfunc (this *TweetCounts) GetTweetCountsPerFrequency(freq string, tweetName string, startTime int, endTime int) []int {\n \n}\n\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * obj := Constructor();\n * obj.RecordTweet(tweetName,time);\n * param_2 := obj.GetTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */",
"__typename":"CodeSnippetNode"
},
{
"lang":"Scala",
"langSlug":"scala",
"code":"class TweetCounts() {\n\n def recordTweet(tweetName: String, time: Int) {\n \n }\n\n def getTweetCountsPerFrequency(freq: String, tweetName: String, startTime: Int, endTime: Int): List[Int] = {\n \n }\n\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = new TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */",
"__typename":"CodeSnippetNode"
},
{
"lang":"Kotlin",
"langSlug":"kotlin",
"code":"class TweetCounts() {\n\n fun recordTweet(tweetName: String, time: Int) {\n \n }\n\n fun getTweetCountsPerFrequency(freq: String, tweetName: String, startTime: Int, endTime: Int): List<Int> {\n \n }\n\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */",
"__typename":"CodeSnippetNode"
},
{
"lang":"Rust",
"langSlug":"rust",
"code":"struct TweetCounts {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TweetCounts {\n\n fn new() -> Self {\n \n }\n \n fn record_tweet(&self, tweet_name: String, time: i32) {\n \n }\n \n fn get_tweet_counts_per_frequency(&self, freq: String, tweet_name: String, start_time: i32, end_time: i32) -> Vec<i32> {\n \n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * let obj = TweetCounts::new();\n * obj.record_tweet(tweetName, time);\n * let ret_2: Vec<i32> = obj.get_tweet_counts_per_frequency(freq, tweetName, startTime, endTime);\n */",
"__typename":"CodeSnippetNode"
},
{
"lang":"PHP",
"langSlug":"php",
"code":"class TweetCounts {\n /**\n */\n function __construct() {\n \n }\n \n /**\n * @param String $tweetName\n * @param Integer $time\n * @return NULL\n */\n function recordTweet($tweetName, $time) {\n \n }\n \n /**\n * @param String $freq\n * @param String $tweetName\n * @param Integer $startTime\n * @param Integer $endTime\n * @return Integer[]\n */\n function getTweetCountsPerFrequency($freq, $tweetName, $startTime, $endTime) {\n \n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * $obj = TweetCounts();\n * $obj->recordTweet($tweetName, $time);\n * $ret_2 = $obj->getTweetCountsPerFrequency($freq, $tweetName, $startTime, $endTime);\n */",
"__typename":"CodeSnippetNode"
},
{
"lang":"TypeScript",
"langSlug":"typescript",
"code":"class TweetCounts {\n constructor() {\n\n }\n\n recordTweet(tweetName: string, time: number): void {\n\n }\n\n getTweetCountsPerFrequency(freq: string, tweetName: string, startTime: number, endTime: number): number[] {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = new TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */",
"__typename":"CodeSnippetNode"
},
{
"lang":"Racket",
"langSlug":"racket",
"code":"(define tweet-counts%\n (class object%\n (super-new)\n (init-field)\n \n ; record-tweet : string? exact-integer? -> void?\n (define/public (record-tweet tweet-name time)\n\n )\n ; get-tweet-counts-per-frequency : string? string? exact-integer? exact-integer? -> (listof exact-integer?)\n (define/public (get-tweet-counts-per-frequency freq tweet-name start-time end-time)\n\n )))\n\n;; Your tweet-counts% object will be instantiated and called as such:\n;; (define obj (new tweet-counts%))\n;; (send obj record-tweet tweet-name time)\n;; (define param_2 (send obj get-tweet-counts-per-frequency freq tweet-name start-time end-time))",
"__typename":"CodeSnippetNode"
},
{
"lang":"Erlang",
"langSlug":"erlang",
"code":"-spec tweet_counts_init_() -> any().\ntweet_counts_init_() ->\n .\n\n-spec tweet_counts_record_tweet(TweetName :: unicode:unicode_binary(), Time :: integer()) -> any().\ntweet_counts_record_tweet(TweetName, Time) ->\n .\n\n-spec tweet_counts_get_tweet_counts_per_frequency(Freq :: unicode:unicode_binary(), TweetName :: unicode:unicode_binary(), StartTime :: integer(), EndTime :: integer()) -> [integer()].\ntweet_counts_get_tweet_counts_per_frequency(Freq, TweetName, StartTime, EndTime) ->\n .\n\n\n%% Your functions will be called as such:\n%% tweet_counts_init_(),\n%% tweet_counts_record_tweet(TweetName, Time),\n%% Param_2 = tweet_counts_get_tweet_counts_per_frequency(Freq, TweetName, StartTime, EndTime),\n\n%% tweet_counts_init_ will be called before every test case, in which you can do some necessary initializations.",
"__typename":"CodeSnippetNode"
},
{
"lang":"Elixir",
"langSlug":"elixir",
"code":"defmodule TweetCounts do\n @spec init_() :: any\n def init_() do\n\n end\n\n @spec record_tweet(tweet_name :: String.t, time :: integer) :: any\n def record_tweet(tweet_name, time) do\n\n end\n\n @spec get_tweet_counts_per_frequency(freq :: String.t, tweet_name :: String.t, start_time :: integer, end_time :: integer) :: [integer]\n def get_tweet_counts_per_frequency(freq, tweet_name, start_time, end_time) do\n\n end\nend\n\n# Your functions will be called as such:\n# TweetCounts.init_()\n# TweetCounts.record_tweet(tweet_name, time)\n# param_2 = TweetCounts.get_tweet_counts_per_frequency(freq, tweet_name, start_time, end_time)\n\n# TweetCounts.init_ will be called before every test case, in which you can do some necessary initializations.",
"envInfo":"{\"cpp\": [\"C++\", \"<p>Compiled with <code> clang 11 </code> using the latest C++ 17 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level two optimization (<code>-O2</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\"], \"java\": [\"Java\", \"<p><code> OpenJDK 17 </code>. Java 8 features such as lambda expressions and stream API can be used. </p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n<p>Includes <code>Pair</code> class from https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html.</p>\"], \"python\": [\"Python\", \"<p><code>Python 2.7.12</code>.</p>\\r\\n\\r\\n<p>Most libraries are already imported automatically for your convenience, such as <a href=\\\"https://docs.python.org/2/library/array.html\\\" target=\\\"_blank\\\">array</a>, <a href=\\\"https://docs.python.org/2/library/bisect.html\\\" target=\\\"_blank\\\">bisect</a>, <a href=\\\"https://docs.python.org/2/library/collections.html\\\" target=\\\"_blank\\\">collections</a>. If you need more libraries, you can import it yourself.</p>\\r\\n\\r\\n<p>For Map/TreeMap data structure, you may use <a href=\\\"http://www.grantjenks.com/docs/sortedcontainers/\\\" target=\\\"_blank\\\">sortedcontainers</a> library.</p>\\r\\n\\r\\n<p>Note that Python 2.7 <a href=\\\"https://www.python.org/dev/peps/pep-0373/\\\" target=\\\"_blank\\\">will not be maintained past 2020</a>. For the latest Python, please choose Python3 instead.</p>\"], \"c\": [\"C\", \"<p>Compiled with <code>gcc 8.2</code> using the gnu99 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level one optimization (<code>-O1</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n\\r\\n<p>For hash table operations, you may use <a href=\\\"https://troydhanson.github.io/uthash/\\\" target=\\\"_blank\\\">uthash</a>. \\\"uthash.h\\\" is included by default. Below are some examples:</p>\\r\\n\\r\\n<p><b>1. Adding an item to a hash.</b>\\r\\n<pre>\\r\\nstruct hash_entry {\\r\\n int id; /* we'll use this field as the key */\\r\\n char name[10];\\r\\n UT_hash_handle hh; /* makes this structure hashable */\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>2. Looking up an item in a hash:</b>\\r\\n<pre>\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n struct hash_entry *s;\\r\\n HASH_FIND_INT(users, &user_id, s);\\r\\n return s;\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>3. Deleting an item in a hash:</b>\\r\\n<pre>\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n HASH_DEL(users, user); \\r\\n}\\r\\n</pre>\\r\\n</p>\"], \"csharp\": [\"C#\", \"<p><a href=\\\"https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9\\\" target=\\\"_blank\\\">C# 10 with .NET 6 runtime</a></p>\\r\\n\\r\\n<p>Your code is compiled with debug flag enabled (<code>/debug</code>).</p>\"], \"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use <a href=\\\"https://github.com/datastructures-js/priority-queue\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and <a href=\\\"https: