-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b4794d
commit 1b53c78
Showing
4 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//{ Driver Code Starts | ||
//Initial Template for Java | ||
import java.util.*; | ||
import java.io.*; | ||
class GFG { | ||
public static void main(String args[]) throws IOException { | ||
BufferedReader read = | ||
new BufferedReader(new InputStreamReader(System.in)); | ||
int t = Integer.parseInt(read.readLine()); | ||
while (t-- > 0) { | ||
int n = Integer.parseInt(read.readLine()); | ||
Solution ob = new Solution(); | ||
|
||
System.out.println(ob.armstrongNumber(n)); | ||
} | ||
} | ||
} | ||
// } Driver Code Ends | ||
|
||
|
||
//User function Template for Java | ||
class Solution | ||
{ | ||
static String armstrongNumber(int n) | ||
{ | ||
// code here | ||
int x = n; | ||
int result = 0; | ||
while(x > 0) | ||
{ | ||
result += Math.pow((x%10), 3); | ||
x = x/10; | ||
} | ||
|
||
return result==n ? "Yes":"No"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(n) | ||
Space complexity - O(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(n*logn) | ||
Space complexity - O(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Solution | ||
{ | ||
public int minIncrementForUnique(int[] nums) | ||
{ | ||
int ans = 0; | ||
int min = 0; | ||
|
||
Arrays.sort(nums); | ||
|
||
for (int num : nums) | ||
{ | ||
ans += Math.max(min - num, 0); | ||
min = Math.max(min, num) + 1; | ||
} | ||
|
||
return ans; | ||
} | ||
} |