Sort by

recency

|

123 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can watch video explanation here : https://youtu.be/Qs9rxqfzTs8

    bool is_smart_number(int num) {
        int val = (int) sqrt(num);
        if(val * val == num)
            return true;
        return false;
    }
    
  • + 0 comments

    import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;

    public class Solution { public static boolean isSmartNumber(int num) { int val = (int) Math.sqrt(num);
    if(num / val == 1) return true; return false; }

    public static void main(String[] args) {
        int test_cases;
        Scanner in = new Scanner(System.in);
        test_cases = in.nextInt();
        int num;
        for(int i = 0; i < test_cases; i++){
            num = in.nextInt();
            boolean ans = isSmartNumber(num);
            if(ans){
                System.out.println("YES");
            }
            else System.out.println("NO");
        }
    }
    

    }


  • + 0 comments

    I didn't understand the approch they want to do. so I think in my way and make changes in a single line of that code. though my output and expected output are same. It's still showing wrong answer. So, I think it not only watching for the output but also watching for whitch line and what changed. Here is my first approch.

    def is_smart_number(num):
        val = num if len([i for i in range(1, num+1) if num % i==0]) % 2 !=0 else num+1
        if num / val == 1:
            return True
        return False
    

    and here is the expected approch.

    def is_smart_number(num):
        val = int(math.sqrt(num))
        if val * val == num:
            return True
        return False
    
  • + 1 comment

    I'm doing this question as a part of Mountblue coding challenge. There is no "Reset" button on the editor. Even my output matches the expected output, it still gives "wrong answer"

    And at the end of the code there is an "undefined" written in teh code editor

  • + 0 comments

    Explanation of what the algorithm is actually doing.

    For any number there will always be a pair of factors, a and b, for that number. Example for 24: 1&24, 2&12, 3&8, 4&6.

    Due to this, the result will by default be an even number. However the only exception is when a number has an integer square root, as the root is only counted once towards the factors.

    So the problem finds the integer root and checks if that root squared is equal to the original number. If so, then the answer is YES.