Tasks Details
easy
Maximize A[P] * A[Q] * A[R] for any triplet (P, Q, R).
Task Score
100%
Correctness
100%
Performance
100%
A non-empty array A consisting of N integers is given. The product of triplet (P, Q, R) equates to A[P] * A[Q] * A[R] (0 ≤ P < Q < R < N).
For example, array A such that:
A[0] = -3 A[1] = 1 A[2] = 2 A[3] = -2 A[4] = 5 A[5] = 6contains the following example triplets:
- (0, 1, 2), product is −3 * 1 * 2 = −6
- (1, 2, 4), product is 1 * 2 * 5 = 10
- (2, 4, 5), product is 2 * 5 * 6 = 60
Your goal is to find the maximal product of any triplet.
Write a function:
function solution(A);
that, given a non-empty array A, returns the value of the maximal product of any triplet.
For example, given array A such that:
A[0] = -3 A[1] = 1 A[2] = 2 A[3] = -2 A[4] = 5 A[5] = 6the function should return 60, as the product of triplet (2, 4, 5) is maximal.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [3..100,000];
- each element of array A is an integer within the range [−1,000..1,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used JavaScript
Time spent on task 38 minutes
Notes
not defined yet
Task timeline
Code: 03:41:32 UTC,
java,
autosave
Code: 03:41:43 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
compareMax(value){
if(value > max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > middle){
this.min = this.middle
this.middle = value
}else if(value > min){
this.min = value
}
}
compareMin(value){
if(value < min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < middle){
this.max = this.middle
this.middle = value
}else if(value < max){
this.max = value
}
}
}
Code: 03:41:53 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > middle){
this.min = this.middle
this.middle = value
}else if(value > min){
this.min = value
}
}
compareMin(value){
if(value < min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < middle){
this.max = this.middle
this.middle = value
}else if(value < max){
this.max = value
}
}
}
Code: 03:42:15 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
compareMax(value){
if(this.max != null && value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:42:25 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
compareMax(value){
if(this.max != null && value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(this.middle != null && value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:42:37 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
compareMax(value){
if(this.max != null && value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(this.middle != null && value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min || ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:43:01 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
compareMax(value){
if(this.max != null && value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(this.middle != null && value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:43:13 UTC,
js,
verify,
result: Failed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Analysis
expand all
Example tests
1.
0.056 s
WRONG ANSWER,
got 0 expected 60
Code: 03:43:32 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
con
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:43:43 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
console.log()
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:44:06 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
console.log()
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log()
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:44:17 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
console.log()
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:44:35 UTC,
js,
verify,
result: Failed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Analysis
expand all
Example tests
1.
0.056 s
WRONG ANSWER,
got 0 expected 60
stdout:
6 5 2 null null null null null null null -2 -3
Code: 03:44:48 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
cons
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:44:58 UTC,
js,
verify,
result: Failed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_negative.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Analysis
expand all
Example tests
1.
0.056 s
WRONG ANSWER,
got 0 expected 60
stdout:
6 5 2 null null null null null null null -2 -3 4 2
Code: 03:45:19 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_positive.max * max_negative.middle * max_negative.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:45:21 UTC,
js,
verify,
result: Passed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_positive.max * max_positive.middle * max_positive.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 null null null null null null null -2 -3 4 2
Code: 03:45:51 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_positive.max * max_positive.middle * max_positive.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:46:00 UTC,
js,
verify,
result: Passed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_positive.max * max_positive.middle * max_positive.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 null null null null null null null -2 -3 4 2
expand all
User tests
1.
0.064 s
OK
function result: 12
function result: 12
stdout:
6 2 1 null null null null null null null -2 -3 3 2
Code: 03:46:21 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
return max_positive.max * max_positive.middle * max_positive.min
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:46:45 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
if(positive_count >= 3){
var pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
return
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:46:55 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
if(positive_count >= 3){
var pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(){
}
return
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:47:26 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
}
return
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:47:36 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 =
}
return
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:47:58 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max
}
return
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:48:16 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max()
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:48:19 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
Analysis
expand all
Example tests
1.
0.060 s
OK
stdout:
6 5 2 null null null null null null null -2 -3 4 2
expand all
User tests
1.
0.060 s
OK
function result: 12
function result: 12
stdout:
6 2 1 null null null null null null null -2 -3 3 2
Code: 03:49:09 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:49:26 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && )
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:49:47 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && )
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:50:10 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
}else if(){
}else if(){
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:50:21 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
}else if(this.middle == null && this.max == null){
}else if(){
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:50:32 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
}else if(this.middle == null && this.max == null){
}else if(this.max == null){
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:50:46 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
}else if(this.max == null){
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:50:56 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.min = value
}else if(this.max == null){
this.min = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:51:10 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:51:25 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:51:53 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:52:04 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}else if(this.middle == null && this.min == null){
this.middle = value
}else if(this.min == null){
this.max = value
}else if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:52:04 UTC,
js,
verify,
result: Failed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}else if(this.middle == null && this.min == null){
this.middle = value
}else if(this.min == null){
this.max = value
}else if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
Analysis
expand all
Example tests
1.
0.056 s
WRONG ANSWER,
got 0 expected 60
stdout:
6 2 null 5 2 1 -3 -2 null null -2 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 0
function result: 0
stdout:
6 2 null 6 2 1 -3 -2 null null -2 -3 3 2
Code: 03:52:35 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.m
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}else if(this.middle == null && this.min == null){
this.middle = value
}else if(this.min == null){
this.max = value
}else if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:52:36 UTC,
js,
verify,
result: Failed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.max * max_positive.min
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}else if(this.middle == null && this.min == null){
this.middle = value
}else if(this.min == null){
this.max = value
}else if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
Analysis
expand all
Example tests
1.
0.056 s
WRONG ANSWER,
got 0 expected 60
stdout:
6 2 null 5 2 1 -3 -2 null null -2 -3 4 2
expand all
User tests
1.
0.060 s
OK
function result: 0
function result: 0
stdout:
6 2 null 6 2 1 -3 -2 null null -2 -3 3 2
Code: 03:53:05 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}else if(this.middle == null && this.min == null){
this.middle = value
}else if(this.min == null){
this.max = value
}else if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:53:06 UTC,
js,
verify,
result: Failed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}else if(this.middle == null && this.min == null){
this.middle = value
}else if(this.min == null){
this.max = value
}else if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
Analysis
expand all
Example tests
1.
0.056 s
WRONG ANSWER,
got 0 expected 60
stdout:
6 2 null 5 2 1 -3 -2 null null -2 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 0
function result: 0
stdout:
6 2 null 6 2 1 -3 -2 null null -2 -3 3 2
Code: 03:53:28 UTC,
js,
verify,
result: Failed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}else if(this.middle == null && this.min == null){
this.middle = value
}else if(this.min == null){
this.min = value
}else if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
Analysis
expand all
Example tests
1.
0.056 s
WRONG ANSWER,
got 12 expected 60
stdout:
6 1 2 5 2 1 -3 -2 null null -2 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 12
function result: 12
stdout:
1 2 6 6 2 1 -3 -2 null null -2 -3 3 2
Code: 03:53:58 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
max_positive.getValue()
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}else if(this.middle == null && this.min == null){
this.middle = value
}else if(this.min == null){
this.min = value
}else if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:54:01 UTC,
js,
verify,
result: Failed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
max_positive.getValue()
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}else if(this.middle == null && this.min == null){
this.middle = value
}else if(this.min == null){
this.min = value
}else if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
Analysis
expand all
Example tests
1.
0.060 s
WRONG ANSWER,
got 12 expected 60
stdout:
1 null null 1 2 null 1 2 5 6 1 2 6 1 2 5 2 1 -3 -2 null null -2 -3 4 2
expand all
User tests
1.
0.060 s
OK
function result: 12
function result: 12
stdout:
1 null null 1 2 null 1 2 6 1 2 6 6 2 1 -3 -2 null null -2 -3 3 2
Code: 03:54:31 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
max_positive.getValue()
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}else if(this.middle == null && this.min == null){
this.middle = value
}else if(this.min == null){
this.min = value
} if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:54:41 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
max_positive.getValue()
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}else if(this.middle == null && this.min == null){
this.middle = value
}else if(this.min == null){
this.min = value
}
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:54:49 UTC,
js,
verify,
result: Passed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
max_positive.getValue()
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
}
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
Analysis
expand all
Example tests
1.
0.060 s
OK
stdout:
1 1 null 2 1 1 5 2 1 6 5 2 6 5 2 5 2 1 -2 -3 null null -2 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 12
function result: 12
stdout:
1 1 null 2 1 1 6 2 1 6 2 1 6 2 1 -2 -3 null null -2 -3 3 2
Code: 03:55:12 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
max_positive.getValue()
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
this.middle = value
}
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:55:22 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
max_positive.getValue()
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
this.middle = value
this.min = value
}
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.min = value
}else if(this.middle == null && this.max == null){
this.middle = value
}else if(this.max == null){
this.max = value
}else if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:55:33 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for(var i=0;i<A.length;i++){
if(A[i] == 0) has_zero = true
else if(A[i] > 0){
max_positive.compareMax(A[i])
max_positive.getValue()
min_positive.compareMin(A[i])
positive_count++
}else{
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >=2 && positive_count > 0)){
var pos_3 = 0
var pos_2_neg_1 = 0
if(positive_count >= 3){
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}else if(negative_count >=2 && positive_count > 0){
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
}else if (has_zero){
return 0
}else{
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue(){
console.log(this.max, this.middle, this.min)
}
compareMax(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
this.middle = value
this.min = value
}
if(value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
}else if(value > this.middle){
this.min = this.middle
this.middle = value
}else if(value > this.min ){
this.min = value
}
}
compareMin(value){
if(this.middle == null && this.max == null && this.min == null){
this.max = value
this.middle = value
this.min = value
}
if(value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
}else if(value < this.middle){
this.max = this.middle
this.middle = value
}else if(value < this.max){
this.max = value
}
}
}
Code: 03:55:35 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
max_positive.getValue()
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
Analysis
expand all
Example tests
1.
0.060 s
OK
stdout:
1 1 1 2 1 1 5 2 1 6 5 2 6 5 2 1 1 1 -2 -3 -3 -3 -3 -3 4 2
expand all
User tests
1.
0.060 s
OK
function result: 12
function result: 12
stdout:
1 1 1 2 1 1 6 2 1 6 2 1 1 1 1 -2 -3 -3 -3 -3 -3 3 2
Code: 03:56:03 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 03:56:24 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 03:56:38 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 03:56:45 UTC,
js,
verify,
result: Passed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 1 1 1 -2 -3 -3 -3 -3 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 12
function result: 12
stdout:
6 2 1 1 1 1 -2 -3 -3 -3 -3 -3 3 2
Code: 03:57:59 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 03:58:08 UTC,
js,
verify,
result: Passed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = null;
this.middle = null;
this.min = null;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 1 1 1 -2 -3 -3 -3 -3 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 12
function result: 12
stdout:
6 2 1 1 1 1 -2 -3 -3 -3 -3 -3 3 2
1.
0.056 s
OK
function result: 18
function result: 18
stdout:
2 1 1 1 1 1 -2 -3 -3 -3 -3 -6 2 3
Code: 04:02:29 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = float('-inf'), float('-inf'), float('-inf');
this.middle = null;
this.min = null;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (this.middle == null && this.max == null && this.min == null) {
this.max = value
this.middle = value
this.min = value
}
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:02:43 UTC,
js,
verify,
result: Failed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = float('-inf');
this.middle = float('-inf');
this.min = float('-inf');
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
Analysis
expand all
Example tests
1.
0.056 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
ReferenceError: float is not defined at new triplet (solution.js:50:9) at solution (solution.js:6:24) at solutionWrapper (/tmp/exec_user_d8pca8pk/exec.js:402:28) at /tmp/exec_user_d8pca8pk/exec.js:428:24
expand all
User tests
1.
0.056 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
ReferenceError: float is not defined at new triplet (solution.js:50:9) at solution (solution.js:6:24) at solutionWrapper (/tmp/exec_user_d8pca8pk/exec.js:402:28) at /tmp/exec_user_d8pca8pk/exec.js:428:24
1.
0.060 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
ReferenceError: float is not defined at new triplet (solution.js:50:9) at solution (solution.js:6:24) at solutionWrapper (/tmp/exec_user_d8pca8pk/exec.js:402:28) at /tmp/exec_user_d8pca8pk/exec.js:428:24
Code: 04:03:19 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = -Infinity;
this.middle = float('-inf');
this.min = float('-inf');
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:03:29 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor() {
this.max = -Infinity;
this.middle = -Infinity;
this.min = -Infinity;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:03:50 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(default) {
this.max = -Infinity;
this.middle = -Infinity;
this.min = -Infinity;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:04:00 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(default) {
this.max = -Infinity;
this.middle = -Infinity;
this.min = -Infinity;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:04:21 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(is) {
this.max = data*Infinity;
this.middle = data*Infinity;
this.min = data*Infinity;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:04:31 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
this.max = data*Infinity;
this.middle = data*Infinity;
this.min = data*Infinity;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:04:52 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet()
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:05:02 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet()
var positive_count = 0
var max_negative = new triplet()
var min_negative = new triplet()
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:05:07 UTC,
js,
verify,
result: Passed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = max_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
Analysis
expand all
Example tests
1.
0.060 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 12
function result: 12
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2
1.
0.060 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -2 -6 2 3
Code: 04:06:14 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * max_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:06:18 UTC,
js,
verify,
result: Passed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
Analysis
expand all
Example tests
1.
0.060 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 12
function result: 12
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2
1.
0.060 s
OK
function result: 24
function result: 24
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -2 -6 2 3
Code: 04:06:44 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.o
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:06:49 UTC,
js,
verify,
result: Passed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
} else if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
Analysis
expand all
Example tests
1.
0.080 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2 pos_2_neg_1 0
expand all
User tests
1.
0.064 s
OK
function result: 12
function result: 12
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2 pos_2_neg_1 0
1.
0.056 s
OK
function result: 24
function result: 24
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -2 -6 2 3 pos_2_neg_1 24
Code: 04:07:23 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:07:24 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2 pos_2_neg_1 36
expand all
User tests
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2 pos_2_neg_1 36
1.
0.056 s
OK
function result: 24
function result: 24
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -2 -6 2 3 pos_2_neg_1 24
Code: 04:08:17 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = (this.max)
this.min = value
} else if (value < this.middle) {
this.min = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:08:43 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.min = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 2 6 Infinity -2 -3 -Infinity Infinity -2 Infinity 4 2 pos_2_neg_1 -Infinity
expand all
User tests
1.
0.056 s
OK
function result: 12
function result: 12
stdout:
6 2 1 2 Infinity 6 -2 -3 -Infinity Infinity -2 Infinity 3 2 pos_2_neg_1 -Infinity
1.
0.056 s
OK
function result: 0
function result: 0
stdout:
2 1 -Infinity Infinity 2 Infinity -2 -3 -6 -2 Infinity -6 2 3 pos_2_neg_1 -Infinity
Code: 04:09:06 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.ma) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.min = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:09:27 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.min = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:10:24 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:10:35 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2 pos_2_neg_1 36
expand all
User tests
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2 pos_2_neg_1 36
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3 pos_2_neg_1 36
Code: 04:10:50 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:10:54 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, 1, -2, -6]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2 pos_2_neg_1 36
expand all
User tests
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2 pos_2_neg_1 36
1.
0.060 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3 pos_2_neg_1 36
1.
0.056 s
OK
function result: 18
function result: 18
stdout:
1 -Infinity -Infinity Infinity Infinity 1 -2 -3 -6 -2 -3 -6 1 3 pos_2_neg_1 18
Code: 04:11:10 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, 0, -2, -6]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2 pos_2_neg_1 36
expand all
User tests
1.
0.060 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2 pos_2_neg_1 36
1.
0.060 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3 pos_2_neg_1 36
1.
0.056 s
OK
function result: 0
function result: 0
stdout:
-Infinity -Infinity -Infinity Infinity Infinity Infinity -2 -3 -6 -2 -3 -6 0 3
Code: 04:11:21 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:11:23 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, 1, -2, -6]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2 pos_2_neg_1 36
expand all
User tests
1.
0.060 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2 pos_2_neg_1 36
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3 pos_2_neg_1 36
1.
0.060 s
OK
function result: 18
function result: 18
stdout:
1 -Infinity -Infinity Infinity Infinity 1 -2 -3 -6 -2 -3 -6 1 3 pos_2_neg_1 18
Code: 04:11:34 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, 1, -2]
Analysis
expand all
Example tests
1.
0.060 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2 pos_2_neg_1 36
expand all
User tests
1.
0.076 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2 pos_2_neg_1 36
1.
0.072 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3 pos_2_neg_1 36
1.
0.080 s
OK
function result: 6
function result: 6
stdout:
1 -Infinity -Infinity Infinity Infinity 1 -2 -3 -Infinity Infinity -2 -3 1 2 pos_2_neg_1 6
Code: 04:11:53 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:11:54 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, -1, -2]
Analysis
expand all
Example tests
1.
0.060 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2 pos_2_neg_1 36
expand all
User tests
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2 pos_2_neg_1 36
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3 pos_2_neg_1 36
1.
0.056 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, non-integer number foundstdout:
-Infinity -Infinity -Infinity Infinity Infinity Infinity -1 -2 -3 -1 -2 -3 0 3
Code: 04:12:01 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
console.log("pos_2_neg_1", pos_2_neg_1)
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, -1, -2, -4]
Analysis
expand all
Example tests
1.
0.064 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2 pos_2_neg_1 36
expand all
User tests
1.
0.080 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2 pos_2_neg_1 36
1.
0.080 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3 pos_2_neg_1 36
1.
0.076 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, non-integer number foundstdout:
-Infinity -Infinity -Infinity Infinity Infinity Infinity -1 -2 -3 -2 -3 -4 0 4
Code: 04:12:42 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:12:53 UTC,
js,
verify,
result: Passed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, -1, -2, -4]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3
1.
0.056 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, non-integer number foundstdout:
-Infinity -Infinity -Infinity Infinity Infinity Infinity -1 -2 -3 -2 -3 -4 0 4 max_2_pos_1_neg -Infinity max_3_neg Infinity
Code: 04:13:55 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:14:09 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg =
if()
= min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:14:23 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if()
= min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:14:33 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if(negative_count >= 2 && positive_count > 0)
= min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:14:53 UTC,
js,
autosave
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if(negative_count >= 2 && positive_count >= 2)
= min_positive.min * min_positive.middle * max_negative.max
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:15:07 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if(negative_count > 0 && positive_count >= 2){
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
=
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:15:18 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if(negative_count > 0 && positive_count >= 2){
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if(){
}
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:15:29 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if(negative_count > 0 && positive_count >= 2){
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if(positive_count <=){
}
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:15:39 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if(negative_count > 0 && positive_count >= 2){
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if(positive_count <= 0){
}
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:15:49 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if(negative_count > 0 && positive_count >= 2){
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if(negative_count >= 3){
}
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:16:30 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if(negative_count > 0 && positive_count >= 2){
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if(negative_count >= 3){
}
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:16:32 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if(negative_count > 0 && positive_count >= 2){
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if(negative_count >= 3){
}
var max_3_neg = min_positive.max * min_positive.middle * min_positive.min
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, -1, -1]
Analysis
expand all
Example tests
1.
0.060 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2
expand all
User tests
1.
0.060 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2
1.
0.060 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3
1.
0.052 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, non-integer number foundstdout:
-Infinity -Infinity -Infinity Infinity Infinity Infinity -1 -1 -3 -1 -1 -3 0 3 max_2_pos_1_neg -Infinity max_3_neg Infinity
Code: 04:16:58 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = min_positive.max * min_positive.middle * min_positive.min
}
var
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:16:59 UTC,
js,
verify,
result: Passed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = min_positive.max * min_positive.middle * min_positive.min
}
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, -1, -1]
Analysis
expand all
Example tests
1.
0.060 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3
1.
0.056 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, integer expected, non-integer number foundstdout:
-Infinity -Infinity -Infinity Infinity Infinity Infinity -1 -1 -3 -1 -1 -3 0 3 max_2_pos_1_neg -Infinity max_3_neg Infinity
Code: 04:17:53 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = max_negative.max * min_positive.middle * min_positive.min
}
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:18:02 UTC,
js,
verify,
result: Passed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = min_negative.max * min_negative.middle * min_negative.min
}
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, -1, -1]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3
1.
0.056 s
OK
function result: -3
function result: -3
stdout:
-Infinity -Infinity -Infinity Infinity Infinity Infinity -1 -1 -3 -1 -1 -3 0 3 max_2_pos_1_neg -Infinity max_3_neg -3
Code: 04:18:15 UTC,
js,
verify,
result: Passed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = min_negative.max * min_negative.middle * min_negative.min
}
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, -1, -1, -555]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3
1.
0.056 s
OK
function result: -1665
function result: -1665
stdout:
-Infinity -Infinity -Infinity Infinity Infinity Infinity -1 -1 -3 -1 -3 -555 0 4 max_2_pos_1_neg -Infinity max_3_neg -1665
Code: 04:18:32 UTC,
js,
autosave
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = max_negative.max * min_negative.middle * min_negative.min
}
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:18:37 UTC,
js,
verify,
result: Passed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = max_negative.max * max_negative.middle * max_negative.min
}
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, -1, -1, -555]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3
1.
0.056 s
OK
function result: -3
function result: -3
stdout:
-Infinity -Infinity -Infinity Infinity Infinity Infinity -1 -1 -3 -1 -3 -555 0 4 max_2_pos_1_neg -Infinity max_3_neg -3
Code: 04:18:47 UTC,
js,
verify,
result: Passed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
max_positive.getValue()
min_positive.getValue()
max_negative.getValue()
min_negative.getValue()
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = max_negative.max * max_negative.middle * max_negative.min
}
console.log("max_2_pos_1_neg", max_2_pos_1_neg)
console.log("max_3_neg", max_3_neg)
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, -1, -1]
Analysis
expand all
Example tests
1.
0.056 s
OK
stdout:
6 5 2 5 2 1 -2 -3 -Infinity Infinity -2 -3 4 2
expand all
User tests
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
6 2 1 6 2 1 -2 -3 -Infinity Infinity -2 -3 3 2
1.
0.060 s
OK
function result: 36
function result: 36
stdout:
2 1 -Infinity Infinity 2 1 -2 -3 -6 -2 -3 -6 2 3
1.
0.060 s
OK
function result: -3
function result: -3
stdout:
-Infinity -Infinity -Infinity Infinity Infinity Infinity -1 -1 -3 -1 -1 -3 0 3 max_2_pos_1_neg -Infinity max_3_neg -3
Code: 04:19:01 UTC,
js,
verify,
result: Passed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
console.log(positive_count, negative_count)
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = max_negative.max * max_negative.middle * max_negative.min
}
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, -1, -1]
Analysis
expand all
User tests
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
3 2
1.
0.056 s
OK
function result: 36
function result: 36
stdout:
2 3
1.
0.056 s
OK
function result: -3
function result: -3
stdout:
0 3
Code: 04:19:08 UTC,
js,
autosave
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = max_negative.max * max_negative.middle * max_negative.min
}
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Code: 04:19:08 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = max_negative.max * max_negative.middle * max_negative.min
}
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, -1, -1]
Analysis
expand all
User tests
1.
0.056 s
OK
function result: 36
function result: 36
1.
0.060 s
OK
function result: 36
function result: 36
1.
0.060 s
OK
function result: -3
function result: -3
Code: 04:19:18 UTC,
js,
verify,
result: Passed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = max_negative.max * max_negative.middle * max_negative.min
}
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
User test case 1:
[-3, 1, 2, -2, 6]
User test case 2:
[-3, 1, 2, -2, -6]
User test case 3:
[-3, -1, -1]
Analysis
expand all
User tests
1.
0.052 s
OK
function result: 36
function result: 36
1.
0.052 s
OK
function result: 36
function result: 36
1.
0.056 s
OK
function result: -3
function result: -3
Code: 04:19:22 UTC,
js,
final,
score: 
100
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// Implement your solution here
var max_positive = new triplet(true)
var min_positive = new triplet(false)
var positive_count = 0
var max_negative = new triplet(true)
var min_negative = new triplet(false)
var negative_count = 0
var has_zero = false
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) has_zero = true
else if (A[i] > 0) {
max_positive.compareMax(A[i])
min_positive.compareMin(A[i])
positive_count++
} else {
max_negative.compareMax(A[i])
min_negative.compareMin(A[i])
negative_count++
}
}
if (positive_count >= 3 || (negative_count >= 2 && positive_count > 0)) {
var pos_3 = 0
var pos_2_neg_1 = 0
if (positive_count >= 3) {
pos_3 = max_positive.max * max_positive.middle * max_positive.min
}
if (negative_count >= 2 && positive_count > 0) {
pos_2_neg_1 = min_negative.middle * min_negative.min * max_positive.max
}
return Math.max(pos_3, pos_2_neg_1)
} else if (has_zero) {
return 0
} else {
//確認該使用2個正數*1個負數還是3個負數
var max_2_pos_1_neg = -Infinity
var max_3_neg = -Infinity
if (negative_count > 0 && positive_count >= 2) {
max_2_pos_1_neg = min_positive.min * min_positive.middle * max_negative.max
}
if (negative_count >= 3) {
max_3_neg = max_negative.max * max_negative.middle * max_negative.min
}
return Math.max(max_2_pos_1_neg, max_3_neg)
}
}
class triplet {
constructor(isMaxCompare) {
var data = isMaxCompare ? -Infinity : Infinity
this.max = data;
this.middle = data;
this.min = data;
}
getValue() {
console.log(this.max, this.middle, this.min)
}
compareMax(value) {
if (value > this.max) {
this.min = this.middle
this.middle = this.max
this.max = value
} else if (value > this.middle) {
this.min = this.middle
this.middle = value
} else if (value > this.min) {
this.min = value
}
}
compareMin(value) {
if (value < this.min) {
this.max = this.middle
this.middle = this.min
this.min = value
} else if (value < this.middle) {
this.max = this.middle
this.middle = value
} else if (value < this.max) {
this.max = value
}
}
}
Analysis summary
The solution obtained perfect score.
Analysis
Detected time complexity:
O(N * log(N))
expand all
Correctness tests
1.
0.052 s
OK
2.
0.052 s
OK
3.
0.052 s
OK
1.
0.052 s
OK
2.
0.052 s
OK
3.
0.052 s
OK
4.
0.052 s
OK
1.
0.052 s
OK
2.
0.052 s
OK
3.
0.052 s
OK
1.
0.052 s
OK
expand all
Performance tests
1.
0.056 s
OK
1.
0.072 s
OK
1.
0.100 s
OK
1.
0.084 s
OK
1.
0.092 s
OK
2.
0.092 s
OK