The code solves a problem finding maximum subarray sum in an array. What i have done here solve the problem properly. But here the new problem is the code is not optimized. It becomes huge when the input is big. Here, Time Complexity = O(n²) Space Complexity = O(1)/constant It gets time limit exceeded when the input is big. So when we run this code on a server, it demand a huge CPU power and increases cost and decreases efficiency. This shows the need of optimal solution. That's we need to learn how to write code optimally. There's an algorithm that solves this problem optimally. Can you guess that? If you can, comment below. This problem is from Leetcode-53. #programming #leetcode #coding
Optimizing Maximum Subarray Sum Algorithm for LeetCode-53
More Relevant Posts
-
Notebook to fine-tune Gemma-4 model is now live on my github repo. ❤️ The notebook walks you step by step on how to train Google's gemma-4, 2 billion parameter model on Multiple-choice Question Answering task with LoRA. We modify the model architecture to inject low rank metrices from scratch and train the model parameters. 🚀 Link to the notebook is in the comments. 🔗 #programming #coding #llm
To view or add a comment, sign in
-
-
Programming looks simple—but behind every line of code, powerful hardware is at work. 💻 Understanding components like CPU, RAM, and storage helps you see what really happens in the backend. Programming languages make it easier, but true mastery comes from knowing how things run underneath. With 2026 bringing advanced tech like AI and faster computing, this knowledge will set you apart. #Programming #SoftwareDevelopment #TechFundamentals #BackendDevelopment #FutureOfTech
To view or add a comment, sign in
-
-
👉 Question-40 A strong understanding of pointers, functions, parameter passing, and side effects is essential in systems programming and embedded development. Assume: --> int = 4 bytes --> Default compiler behavior 👉 What will be the output of the following code❓ #include <stdio.h> void fun(int *p, int q) { *p = *p + q; q = q + 10; } int main() { int a = 5, b = 10; fun(&a, b); printf("%d %d\n", a, b); return 0; } Options: A) 15 20 B) 15 10 C) 5 20 D) 5 10 💬 Kindly drop your answer in the comments along with your reasoning. ⚠️ Small hint: --> *p modifies original variable --> q is passed by value --> Changes to q do NOT reflect in main() #CProgramming #EmbeddedSystems #FirmwareDevelopment #Pointers
To view or add a comment, sign in
-
👉 Question-39 A strong understanding of pointers, functions, pointer arithmetic, and variable scope is essential in systems programming and embedded development. Assume: --> int = 4 bytes --> Default compiler behavior 👉 What will be the output of the following code❓ #include <stdio.h> void fun(int *p) { int y = 30; p = &y; *p = *p + 10; } int main() { int x = 20; int *ptr = &x; fun(ptr); printf("%d\n", x); return 0; } Options: A) 20 B) 30 C) 40 D) Garbage value 💬 Kindly drop your answer in the comments along with your reasoning. ⚠️ Small hint: --> Pointer is passed by value --> Changing p does NOT affect original pointer --> y is local to function #CProgramming #EmbeddedSystems #FirmwareDevelopment #Pointers
To view or add a comment, sign in
-
👉 Question-35 A strong understanding of pointers, functions, and parameter passing is essential in systems programming and embedded development. Assume: --> int = 4 bytes --> Default compiler behavior 👉 What will be the output of the following code❓ #include <stdio.h> void fun(int *p) { int x = 20; p = &x; } int main() { int a = 10; int *ptr = &a; fun(ptr); printf("%d\n", *ptr); return 0; } Options: A) 10 B) 20 C) Garbage value D) Runtime error 💬 Kindly drop your answer in the comments along with your reasoning. ⚠️ Small hint: --> Pointer is passed by value --> Changing p inside function does NOT change original pointer --> Think about scope of variable x #CProgramming #EmbeddedSystems #FirmwareDevelopment #Pointers
To view or add a comment, sign in
-
👉 Question-48 A strong understanding of memory layout, pointers, arrays, and function behavior is essential in systems programming and embedded development. Assume: --> int = 4 bytes --> Default compiler behavior 👉 What will be the output of the following code❓ #include <stdio.h> void fun(int arr[]) { printf("%lu ", sizeof(arr)); } int main() { int arr[10]; printf("%lu ", sizeof(arr)); fun(arr); return 0; } Options: A) 40 40 B) 40 4 C) 4 40 D) 4 4 💬 Kindly drop your answer in the comments along with your reasoning. ⚠️ Small hint: --> In main(), arr is an array --> In function, arr decays to pointer --> sizeof(pointer) ≠ sizeof(array) #CProgramming #EmbeddedSystems #FirmwareDevelopment #Pointers
To view or add a comment, sign in
-
👉 Question-44 A strong understanding of dynamic memory allocation, pointers, and memory management is essential in systems programming and embedded development. Assume: --> int = 4 bytes --> Default compiler behavior 👉 What will be the output of the following code❓ #include <stdio.h> #include <stdlib.h> int main() { int *p = (int *)malloc(sizeof(int) * 3); p[0] = 10; p[1] = 20; free(p); p[2] = 30; printf("%d\n", p[2]); return 0; } Options: A) 30 B) 0 C) Garbage value D) Runtime error / undefined behavior 💬 Kindly drop your answer in the comments along with your reasoning. ⚠️ Small hint: --> Accessing memory after free() is undefined behavior --> Memory may or may not be accessible --> Dangerous bug in embedded systems #CProgramming #EmbeddedSystems #FirmwareDevelopment #Pointers
To view or add a comment, sign in
-
👉 Question-57 A strong understanding of double pointers, arrays, and pointer arithmetic inside functions is essential in systems programming and embedded development. Assume: --> int = 4 bytes --> Default compiler behavior 👉 What will be the output of the following code❓ #include <stdio.h> void fun(int **p) { (*p) += 2; } int main() { int arr[] = {10, 20, 30, 40}; int *ptr = arr; fun(&ptr); printf("%d %d\n", ptr[0], ptr[-1]); return 0; } Options: A) 30 20 B) 30 10 C) 20 10 D) Garbage value 💬 Kindly drop your answer in the comments along with your reasoning. ⚠️ Small hint: --> Pointer moves forward by 2 positions --> ptr[0] → arr[2] --> ptr[-1] → arr[1] #CProgramming #EmbeddedSystems #FirmwareDevelopment #Pointers
To view or add a comment, sign in
-
Cycle Sort is not just another sorting algorithm, it is provably impossible to do fewer writes. Period. Cycle Sort follows where each element belongs, places it, picks up the displaced one, and follows that element. It continues chain after chain until every cycle closes. This is group theory disguised as a sorting algorithm. By minimizing writes to memory, Cycle Sort achieves the theoretical lower bound, making it optimal for scenarios where write operations are expensive, such as flash memory or EEPROM storage. Every element moves directly to its final position with no unnecessary swaps, proving that sometimes the most elegant solution is also the most mathematically efficient. #CycleSort #Programming #CodingLife #TechEducation #Algorithms #SortingAlgorithm #GroupTheory #OptimalAlgorithm #MemoryEfficient #ComputerScience #WriteOptimized #AlgorithmDesign #Coding #Developer #TechLearning #DataStructures #ProgrammingLife #CodeSmart #AlgorithmArt #ProvablyOptimal
To view or add a comment, sign in
-
👉 Question-41 A strong understanding of strings, pointers, pointer arithmetic, and memory behavior is essential in systems programming and embedded development. Assume: --> char = 1 byte --> Default compiler behavior 👉 What will be the output of the following code❓ #include <stdio.h> int main() { char str[] = "ABCDE"; char *p = str; p[2] = '\0'; printf("%s %lu %lu\n", str, sizeof(str), strlen(p)); return 0; } Options: A) ABCDE 6 5 B) AB 6 2 C) AB 5 2 D) ABC 6 3 💬 Kindly drop your answer in the comments along with your reasoning. ⚠️ Small hint: --> '\0' terminates string early --> sizeof gives total array size --> strlen stops at first '\0' #CProgramming #EmbeddedSystems #FirmwareDevelopment #Pointers
To view or add a comment, sign in
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Code URL: https://gist.github.com/mohammadhasansojib/9cf29e66f32fbc93c1fdef6c27a5d79f