Skip to content

Commit

Permalink
feat: DCC 09-11-2024 added.
Browse files Browse the repository at this point in the history
  • Loading branch information
cvalingam committed Nov 9, 2024
1 parent 7f96bd3 commit 1a4d7ed
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
21 changes: 21 additions & 0 deletions solutions/1006. Clumsy Factorial/1006.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Solution
{
public int Clumsy(int n)
{
if (n == 1)
return 1;
if (n == 2)
return 2;
if (n == 3)
return 6;
if (n == 4)
return 7;
if (n % 4 == 1)
return n + 2;
if (n % 4 == 2)
return n + 2;
if (n % 4 == 3)
return n - 1;
return n + 1;
}
}
25 changes: 25 additions & 0 deletions solutions/3133. Minimum Array End/3133.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Solution
{
public long MinEnd(int n, int x)
{
// Set x's 0s with (n - 1)'s LSb-to-MSb bits, preserving x's 1s. This
// operation increases x for (n - 1) iterations while preserving x's 1s.
int kMaxBit = (int)(Math.Log2(n) + Math.Log2(x) + 2);
long k = n - 1;
long ans = x;
int kBinaryIndex = 0;

for (int i = 0; i < kMaxBit; ++i)
{
if ((ans >> i & 1) == 0)
{
// Set x's 0 with k's bit if the running bit of k is 1.
if ((k >> kBinaryIndex & 1) == 1)
ans |= 1L << i;
++kBinaryIndex;
}
}

return ans;
}
}

0 comments on commit 1a4d7ed

Please sign in to comment.