-
Notifications
You must be signed in to change notification settings - Fork 0
/
mostfrequentint.html
199 lines (196 loc) · 7.72 KB
/
mostfrequentint.html
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html>
<html lang="en">
<head>
<title>MostFrequentInt</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="lib/codemirror.css" />
<link rel="stylesheet" href="theme/monokai.css" />
<link rel="stylesheet" href="addon/hint/show-hint.css" />
<link rel="stylesheet" href="addon/lint/lint.css" />
<link rel="stylesheet" href="css/practice.css" />
<link rel="stylesheet" href="css/nav.css" type="text/css" />
<script src="lib/codemirror.js"></script>
<script src="mode/javascript/javascript.js"></script>
<script src="https://unpkg.com/jshint@2.9.6/dist/jshint.js"></script>
<script src="addon/lint/lint.js"></script>
<script src="addon/lint/javascript-lint.js"></script>
<script src="addon/selection/active-line.js"></script>
<script src="addon/edit/closebrackets.js"></script>
<script src="addon/edit/matchbrackets.js"></script>
<script src="addon/hint/show-hint.js"></script>
<script src="addon/hint/javascript-hint.js"></script>
</head>
<body>
<nav>
<div id="nav" class="nav">
<ul>
<li><a href="index.html" class="nav-a" draggable="false">Practice</a></li>
<li><a href="leaderboard.html" class="nav-a" draggable="false">Leaderboard</a></li>
<li id="profile" style="display: none"><a href="/profile" class="nav-a" draggable="false">Profile</a></li>
<li id="login"><a href="#" onclick="return logInGoogle();" class="nav-a" draggable="false">Login</a></li>
<li id="logout" style="display: none">
<a href="#" onclick="return logOutGoogle();" class="nav-a" draggable="false">Logout</a>
</li>
<li class="navname">
<p class="name">Code Practice</p>
</li>
</ul>
</div>
<div class="navbar-cont">
<div class="navbar-hamburger-menu">
<span></span>
<span></span>
<span></span>
</div>
<div class="navbarname">
<p class="name">Code Practice</p>
</div>
</div>
</nav>
<div class="page-container">
<div class="content-wrapper">
<div class="documentation-cont">
<div id="documentation" class="documentation">
<p class="doc-header-upper"><strong>MostFrequentInt</strong></p>
<p class="doc-header-lower"><span class="doc-difficulty medium">Medium</span> <img id="bookmark"
src="svg/bookmark.svg" width="14" height="14"></img></p>
<p>Given an array of integers, return the most frequent integer.</p>
<p><em>If multiple numbers are tied for highest frequency, return the largest of them.</em></p>
<p>
<strong>Parameter(s):</strong>
<ul>
<li><em>arr:</em> an array of integers</li>
</ul>
</p>
<p>
<strong>Returns:</strong>
<ul>
<li><em>integer:</em> the most frequent integer</li>
</ul>
</p>
<p>
<strong>Constraints:</strong>
<ul>
<li><code>arr ≠ null</code></li>
<li><code>1 ≤ arr.length ≤ 1000</code></li>
<li><code>-2147483647 ≤ arr[i] ≤ 2147483647</code></li>
</ul>
</p>
<p>
<strong>Example 1:</strong>
<p>Input:</p>
<div class="code-sample"><code>[1,2,3,1]</code></div>
<p>Output:</p>
<div class="code-sample"><code>1</code></div>
</p>
<p>
<strong>Example 2:</strong>
<p>Input:</p>
<div class="code-sample"><code>[1,2,3]</code></div>
<p>Output:</p>
<div class="code-sample"><code>3</code></div>
</p>
<p>
<strong>Example 3:</strong>
<p>Input:</p>
<div class="code-sample"><code>[4]</code></div>
<p>Output:</p>
<div class="code-sample"><code>4</code></div>
</p>
</div>
<button class="show-button" id="show-more">Show More</button>
<button class="show-button" id="show-less" hidden>Show Less</button>
</div>
<div class="code-cont">
<textarea id="code" name="code">
function mostFrequentInt(arr) {
return -1;
}</textarea>
<div id="remember-code-cont" style="text-align: center"></div>
</div>
<div class="post-code-cont">
<button id="run-tests">Run Tests</button>
<div id="progress-wrap" class="progress-wrap" hidden>
<div id="progress-cont" class="progress-cont">
<div id="progress-bar" class="progress-bar"></div>
</div>
<span>Ran <span id="ran-tests">0</span> tests</span>
</div>
<div id="tests" class="tests-cont"></div>
</div>
</div>
<footer>
<div class="container">
<span>Copyright © 2021 CodePractice
</span><a href="/about-us">About Us</a><a href="/privacy">Privacy
Policy</a><a href="/roadmap">Roadmap</a>
</div>
</footer>
</div>
</body>
<script type="text/javascript" src="js/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="js/nav.js"></script>
<script type="text/javascript" src="js/preload.js"></script>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
theme: "default",
styleActiveLine: true,
gutters: ["CodeMirror-lint-markers"],
lint: true,
autoCloseBrackets: true,
matchBrackets: true,
extraKeys: { "Ctrl-Space": "autocomplete" },
mode: { name: "javascript", globalVars: false },
});
if (window.localStorage.getItem("mostFrequentInt") != null) {
$("#remember-code-cont").append(
"<p " +
"style='margin: 0; padding: 5px;'>" +
"Your previous code was restored. " +
"<span id='reset-to-default' style='text-decoration: underline; " +
"cursor: pointer;'>Reset code to default</span>" +
"<img src='svg/x-icon.svg' width='16' height='16' class='fas fa-times' id='close-remember-code-cont' style='float: right; cursor: pointer;'></i></p>"
);
editor.setValue(window.localStorage.getItem("mostFrequentInt"));
}
$("#close-remember-code-cont").click(function () {
$("#remember-code-cont").hide();
});
$("#reset-to-default").click(function () {
window.localStorage.removeItem("mostFrequentInt");
location.reload();
});
editor.on("change", function (cm, change) {
window.localStorage.setItem("mostFrequentInt", editor.getValue());
});
</script>
<script src="https://www.gstatic.com/firebasejs/8.1.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.1.1/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.1.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.1.1/firebase-database.js"></script>
<script src="js/app.js"></script>
<script src="js/practice.js"></script>
<script type="text/javascript" src="js/tester.js"></script>
<script src="js/confetti.min.js"></script>
<script>
const ref = {
tests: [
{ func: "return mostFrequentInt([1,2,1]);", ans: 1 },
{ func: "return mostFrequentInt([-2,3,-5,-2]);", ans: -2 },
{ func: "return mostFrequentInt([1,2,3,10,12,15,20,15,18,16," + "19,18,19,4,5,9,19,10,19]);", ans: 19 },
{ func: "return mostFrequentInt([0,1,0,1,0,1,0,1,0,1,1]);", ans: 1 },
{ func: "return mostFrequentInt([5,5,6,6,5,6,5]);", ans: 5 },
{ func: "return mostFrequentInt([1,2,3,4,5,1,2,2]);", ans: 2 },
{ func: "return mostFrequentInt([2,3,3,3,3,3,2]);", ans: 3 },
{ func: "return mostFrequentInt([1,2,4,3]);", ans: 4 },
{ func: "return mostFrequentInt([1,2,4,3,4,3]);", ans: 4 },
{ func: "return mostFrequentInt([1]);", ans: 1 },
],
};
$("#run-tests").click(function () {
runtests(ref, "mostFrequentInt");
});
</script>
</html>