Skip to content

Commit c7f1a66

Browse files
committed
leetcode 662
1 parent a1ea3a0 commit c7f1a66

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
int solve(){
11+
long long n;
12+
cin>>n;
13+
long long mini = 0x3f3f3f3f3f3f3f3f, maxo = 0;
14+
// cout<<"mini "<<mini<<" "<<LONG_MAX<<" "<<mini-LONG_MAX<<endl;
15+
for(long long i=1;i*i*i<=n;i++){
16+
if(n%i==0){
17+
for(long long j=1;j*j<=(n/i);j++){
18+
if((n/i)%j==0){
19+
long long k=(n/i)/j;
20+
maxo = max(maxo, (i + 1) * (j + 2) * (k + 2));
21+
maxo = max(maxo, (i + 2) * (j + 1) * (k + 2));
22+
maxo = max(maxo, (i + 2) * (j + 2) * (k + 1));
23+
mini = min(mini, (i + 1) * (j + 2) * (k + 2));
24+
mini = min(mini, (i + 2) * (j + 1) * (k + 2));
25+
mini = min(mini, (i + 2) * (j + 2) * (k + 1));
26+
}
27+
}
28+
}
29+
}
30+
cout<<mini-n<<" "<<maxo-n<<endl;
31+
return 0;
32+
}
33+
int main()
34+
{
35+
int testCase=1;
36+
while(testCase--){
37+
solve();
38+
}
39+
return 0;
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
int widthOfBinaryTree(TreeNode *root)
15+
{
16+
if (!root)
17+
{
18+
return 0;
19+
}
20+
21+
queue<pair<TreeNode *, unsigned long long>> q;
22+
q.push(make_pair(root, 1)); // push root node with its index as 1
23+
24+
int maxWidth = 0;
25+
while (!q.empty())
26+
{
27+
int size = q.size();
28+
unsigned long long left = q.front().second; // get the leftmost index of current level
29+
unsigned long long right = 0; // initialize right index for current level
30+
for (int i = 0; i < size; i++)
31+
{
32+
TreeNode *node = q.front().first;
33+
right = q.front().second; // update right index for current node
34+
q.pop();
35+
36+
if (node->left)
37+
{
38+
q.push(make_pair(node->left, 2 * right)); // push left child with index 2 * right
39+
}
40+
if (node->right)
41+
{
42+
q.push(make_pair(node->right, 2 * right + 1)); // push right child with index 2 * right + 1
43+
}
44+
}
45+
maxWidth = max(maxWidth, (int)(right - left + 1)); // update the maximum width of the level
46+
}
47+
48+
return maxWidth;
49+
}
50+
};

0 commit comments

Comments
 (0)