Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Ben Pereira
Ben Pereira

Posted on

Leetcode — 2769. Find the Maximum Achievable Number

This is an easy problem with description being:

Given two integers, num and t. A number is achievable if it can become equal to num after applying the following operation:

Increase or decrease the number by 1, and simultaneously increase or decrease num by 1.

Return the maximum achievable number after applying the operation at most t times.

This problem is more of text interpretation than anything else. Basically you have a number and you have a number of operations (t). Every time an operation runs it increases or decreases number by 1.

Maximum achievable number would be the biggest number after all t operations (that increase/decrease by one).

To summarize, to solve this you need basically multiply the amount of operations by two (since there is two operations inside the main one) and sum with num.

class Solution {    public int theMaximumAchievableX(int num, int t) {        return num + 2 * t;    }}
Enter fullscreen modeExit fullscreen mode

Runtime: 1 ms, faster than 100.00% of Java online submissions for Find the Maximum Achievable Number.

Memory Usage: 41.3 MB, less than 63.18% of Java online submissions for Find the Maximum Achievable Number.


That’s it! If there is anything thing else to discuss feel free to drop a comment, if I missed anything let me know so I can update accordingly.

Until next post! :)

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I'm a ninja from multiverse that aims to share coding knowledge for everyone!
  • Joined

More fromBen Pereira

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp