Skip to content

Latest commit

 

History

History
139 lines (118 loc) · 3.42 KB

_2979. Most Expensive Item That Can Not Be Bought.md

File metadata and controls

139 lines (118 loc) · 3.42 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 29, 2024

Last updated : July 29, 2024


Related Topics : Math, Dynamic Programming, Number Theory

Acceptance Rate : 79.85 %


The chicken mcnugget theorem hehe

This boils down to an induction proof for the postage problem. After a certain point, you can generate any value since you can fill in all the values between two values somehow, then just add the smaller denomination from a starting point.

This is solvable via the chicken mcnugget theorem


Solutions

C

int mostExpensiveItem(int primeOne, int primeTwo) {
    return primeOne * primeTwo - primeOne - primeTwo;
}

C++

class Solution {
public:
    int mostExpensiveItem(int primeOne, int primeTwo) {
        return primeOne * primeTwo - primeOne - primeTwo;
    }
};

Go

func mostExpensiveItem(primeOne int, primeTwo int) int {
    return primeOne * primeTwo - primeOne - primeTwo;
}

Java

class Solution {
    public int mostExpensiveItem(int primeOne, int primeTwo) {
        return primeOne * primeTwo - primeOne - primeTwo;
    }
}

JavaScript

/**
 * @param {number} primeOne
 * @param {number} primeTwo
 * @return {number}
 */
var mostExpensiveItem = function(primeOne, primeTwo) {
    return primeOne * primeTwo - primeOne - primeTwo;
};

Kotlin

class Solution {
    fun mostExpensiveItem(primeOne: Int, primeTwo: Int): Int {
        return primeOne * primeTwo - primeOne - primeTwo;
    }
}

Python

class Solution:
    def mostExpensiveItem(self, primeOne: int, primeTwo: int) -> int:
        return primeOne * primeTwo - primeOne - primeTwo

Rust

impl Solution {
    pub fn most_expensive_item(prime_one: i32, prime_two: i32) -> i32 {
        return prime_one * prime_two - prime_one - prime_two;
    }
}

Swift

class Solution {
    func mostExpensiveItem(_ primeOne: Int, _ primeTwo: Int) -> Int {
        return primeOne * primeTwo - primeOne - primeTwo;
    }
}

TypeScript

function mostExpensiveItem(primeOne: number, primeTwo: number): number {
    return primeOne * primeTwo - primeOne - primeTwo;
};