From 1e78025a739c47aad8a90558a5dbb542a145e735 Mon Sep 17 00:00:00 2001 From: siri-chandana-macha Date: Fri, 11 Oct 2024 22:01:58 +0530 Subject: [PATCH 1/6] Create Least Common Multiple (LCM) Calculation\ --- .../Least Common Multiple (LCM) Calculation\\" | 1 + 1 file changed, 1 insertion(+) create mode 100644 "Mathematical Algorithms/Least Common Multiple (LCM) Calculation\\" diff --git "a/Mathematical Algorithms/Least Common Multiple (LCM) Calculation\\" "b/Mathematical Algorithms/Least Common Multiple (LCM) Calculation\\" new file mode 100644 index 00000000..8b137891 --- /dev/null +++ "b/Mathematical Algorithms/Least Common Multiple (LCM) Calculation\\" @@ -0,0 +1 @@ + From e63ce0854a0f9a2522c21d07cef5452a91b67792 Mon Sep 17 00:00:00 2001 From: siri-chandana-macha Date: Fri, 11 Oct 2024 22:04:09 +0530 Subject: [PATCH 2/6] Delete Mathematical Algorithms/Least Common Multiple (LCM) Calculation\ --- .../Least Common Multiple (LCM) Calculation\\" | 1 - 1 file changed, 1 deletion(-) delete mode 100644 "Mathematical Algorithms/Least Common Multiple (LCM) Calculation\\" diff --git "a/Mathematical Algorithms/Least Common Multiple (LCM) Calculation\\" "b/Mathematical Algorithms/Least Common Multiple (LCM) Calculation\\" deleted file mode 100644 index 8b137891..00000000 --- "a/Mathematical Algorithms/Least Common Multiple (LCM) Calculation\\" +++ /dev/null @@ -1 +0,0 @@ - From f7ee0d3a3499cd4455c37277b07079c3768280b0 Mon Sep 17 00:00:00 2001 From: siri-chandana-macha Date: Sat, 12 Oct 2024 07:17:09 +0530 Subject: [PATCH 3/6] Create README.md --- Mathematical Algorithms/Least Common Multiple (LCM)/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Mathematical Algorithms/Least Common Multiple (LCM)/README.md diff --git a/Mathematical Algorithms/Least Common Multiple (LCM)/README.md b/Mathematical Algorithms/Least Common Multiple (LCM)/README.md new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Mathematical Algorithms/Least Common Multiple (LCM)/README.md @@ -0,0 +1 @@ + From a3ff8f26da2d82ad4471bae8488114c6dc6d9e40 Mon Sep 17 00:00:00 2001 From: siri-chandana-macha Date: Sat, 12 Oct 2024 07:19:37 +0530 Subject: [PATCH 4/6] Delete Mathematical Algorithms/Least Common Multiple (LCM) directory --- Mathematical Algorithms/Least Common Multiple (LCM)/README.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Mathematical Algorithms/Least Common Multiple (LCM)/README.md diff --git a/Mathematical Algorithms/Least Common Multiple (LCM)/README.md b/Mathematical Algorithms/Least Common Multiple (LCM)/README.md deleted file mode 100644 index 8b137891..00000000 --- a/Mathematical Algorithms/Least Common Multiple (LCM)/README.md +++ /dev/null @@ -1 +0,0 @@ - From 1c406eb3f755c8ec4484130e8b764d5f8b7d824a Mon Sep 17 00:00:00 2001 From: Siri Chandana Macha Date: Fri, 8 Nov 2024 21:02:50 +0530 Subject: [PATCH 5/6] Create READ ME.md --- .../Max Consecutive Set Bits/READ ME.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Bit Manipulation/Max Consecutive Set Bits/READ ME.md diff --git a/Bit Manipulation/Max Consecutive Set Bits/READ ME.md b/Bit Manipulation/Max Consecutive Set Bits/READ ME.md new file mode 100644 index 00000000..7c982966 --- /dev/null +++ b/Bit Manipulation/Max Consecutive Set Bits/READ ME.md @@ -0,0 +1,15 @@ +## Description +The Max Consecutive Set Bits problem requires finding the longest contiguous sequence of 1s in the binary representation of a given integer. For instance, for the integer 29, whose binary representation is 11101, the longest sequence of consecutive 1s is 3. + +### Input +An integer n. + +### Output +An integer representing the length of the longest contiguous sequence of 1s in the binary representation of n. + +### Constraints + +0≤n≤10^9 + +### Time Complexity +The time complexity is **O(logn)**, which is efficient because we only need to examine each bit in the binary representation of n, which takes at most O(logn) time. From 7bda198ce5f516d1fd8f77ff377c139983f4459f Mon Sep 17 00:00:00 2001 From: Siri Chandana Macha Date: Fri, 8 Nov 2024 21:07:50 +0530 Subject: [PATCH 6/6] Create program.c --- .../Max Consecutive Set Bits/program.c | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Bit Manipulation/Max Consecutive Set Bits/program.c diff --git a/Bit Manipulation/Max Consecutive Set Bits/program.c b/Bit Manipulation/Max Consecutive Set Bits/program.c new file mode 100644 index 00000000..580a748e --- /dev/null +++ b/Bit Manipulation/Max Consecutive Set Bits/program.c @@ -0,0 +1,30 @@ +#include + +int maxConsecutiveOnes(int n) { + int maxCount = 0, currentCount = 0; + + while (n > 0) { + // Check if the last bit is 1 + if (n & 1) { + currentCount++; + if (currentCount > maxCount) + maxCount = currentCount; + } else { + currentCount = 0; + } + // Right shift the bits of n by 1 to check the next bit + n >>= 1; + } + return maxCount; +} + +int main() { + int n; + printf("Enter a number: "); + scanf("%d", &n); + + int result = maxConsecutiveOnes(n); + printf("Maximum consecutive set bits: %d\n", result); + + return 0; +}