This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getTopStocks(stocks, prices) { | |
// Step 1: Calculate average for each stock | |
const n = stocks.length; | |
const averages = []; | |
for (let i = 0; i < n; i++) { | |
let sum = 0; | |
for (let j = 0; j < prices.length; j++) { | |
sum += prices[j][i]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseRobotFile(robotLines) { | |
const rulesByAgent = { DoeBot: [], "*": [] }; | |
let currentRelevantAgentKey = null; | |
const UA_PREFIX = "User-agent:"; | |
const DIS_PREFIX = "Disallow:"; | |
for (const rawLine of robotLines) { | |
const line = rawLine.trim(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
// The Gson imports shown in the screenshot (com.google.gson.*) are not needed for this problem's core logic. | |
public class Player { // Assuming CoderPad uses a class named Player or similar | |
/** | |
* Calculates the sequence of actions to transform an atom from a starting state | |
* (protonsStart, neutronsStart) to a target state (protonsTarget, neutronsTarget). | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Solution { | |
/** | |
* @param clusterSize The cluster size of a disk (in bytes). | |
* @param fileSize The size of a file (in bytes). | |
* @return The "size on disk" of this file, on this disk (in bytes). | |
*/ | |
public static int computeSizeOnDisk(int clusterSize, int fileSize) { | |
// Calculate the number of clusters needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string[]} robotLines The lines of the robots.txt file (only ASCII characters, no newline | |
* characters at the end was already removed). | |
* @return {string[]} All the disallowed url patterns that apply to your search engine. | |
*/ | |
function parseRobotFile(robotLines) { | |
let doeBotRules = []; | |
let wildcardRules = []; | |
// This variable tracks the agent type for the current section being processed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Given a list of daily stock prices, return the three stocks with the highest average price. | |
* | |
* @param {string[]} stocks - An array of strings, representing the stock names. | |
* @param {number[][]} prices - An array of arrays, where prices[i] is an array of daily prices for stocks[i]. | |
* @returns {string[]} An array containing the names of up to three stocks with the highest average price, | |
* sorted by decreasing average value. | |
*/ | |
function getTopStocks(stocks, prices) { | |
// Step 1: Calculate the average price for each stock and store it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule } from '@angular/core'; | |
import {MatCheckboxModule} from '@angular/material/checkbox'; | |
import {MatButtonModule} from '@angular/material/button'; | |
import {MatInputModule} from '@angular/material/input'; | |
import {MatAutocompleteModule} from '@angular/material/autocomplete'; | |
import {MatDatepickerModule} from '@angular/material/datepicker'; | |
import {MatFormFieldModule} from '@angular/material/form-field'; | |
import {MatRadioModule} from '@angular/material/radio'; | |
import {MatSelectModule} from '@angular/material/select'; | |
import {MatSliderModule} from '@angular/material/slider'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
#include <LiquidCrystal.h> | |
#include "DHT.h" | |
#define DHTPIN 2 | |
int threshold; | |
int ac=3; | |
int curtain=5; | |
Servo myservo; | |
#define DHTTYPE DHT11 | |
// initialize the library with the numbers of the interface pins |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module mul_test_bench; | |
reg [15:0] data_in; | |
reg clk, start; | |
wire done; | |
datapath DP (eqz, LdA, LdB, LdP, clrP, decB, data_in, clk); | |
controller CON (LdA, LdB, LdP, clrP, decB, done, clk, eqz, start); | |
initial | |
begin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module controller (LdA, LdB, LdP, clrP, decB, done, clk, eqz, start); | |
input clk, eqz, start; | |
output reg LdA, LdB, LdP, clrP, decB, done; | |
reg [2:0] state; | |
parameter s0=3'b000, s1=3'b001, s2=3'b010, s3=3'b011, s4=3'b100; | |
always @(posedge clk) | |
begin | |
case (state) | |
s0: if (start) state <= s1; |
NewerOlder