LeetCode POTD š«: Description: Given two positive integersĀ nĀ andĀ k, the binary stringĀ SnĀ is formed as follows: -> S1 = "0" -> Si = Si - 1 + "1" + reverse(invert(Si - 1))Ā forĀ i > 1 WhereĀ +Ā denotes the concatenation operation,Ā reverse(x)Ā returns the reversed stringĀ x, andĀ invert(x)Ā inverts all the bits inĀ xĀ (0Ā changes toĀ 1Ā andĀ 1Ā changes toĀ 0). For example, the first four strings in the above sequence are: -> S1 = "0" -> S2 = "011" -> S3 = "0111001" -> S4 = "011100110110001" ReturnĀ theĀ kthĀ bitĀ inĀ Sn. It is guaranteed thatĀ kĀ is valid for the givenĀ n. Here's my solution: https://lnkd.in/gQgs6AN9 #Python #DSA #Leetcode #DailyChallenge
LeetCode POTD: Binary String Generation and Kth Bit Extraction
More Relevant Posts
-
Day 67 of 365 Days of code the infamous brainrot number Qn 1) Reorder list You are given the head of a singly linked-list. The positions of a linked list ofĀ length = 7Ā for example, can intially be represented as: [0, 1, 2, 3, 4, 5, 6] Reorder the nodes of the linked list to be in the following order: [0, 6, 1, 5, 2, 4, 3] Notice that in the general case for a list ofĀ length = nĀ the nodes are reordered to be in the following order: [0, n-1, 1, n-2, 2, n-3, ...] You may not modify the values in the list's nodes, but instead you must reorder the nodes themselves. approach: use 5 pointers(scary :")) #365daysOfCode #NeetCodeĀ #leetcodeĀ #DSAĀ #python #LeetCode #ProblemSolvingĀ #Algorithms #365dayschallenge
To view or add a comment, sign in
-
-
Day 62 of 365 Days of code Qn1) insert into a binary searchš³ Approach: recursion def insert(root,val): if root==None: set root=Treenode(val) return root elif root.val<val: root.right=insert(root.right,val) else: root.left=insert(root.left,val) return root Sleep well during exams bud, a piece of advice :"). #365daysOfCode #NeetCodeĀ #leetcodeĀ #DSAĀ #python #LeetCode #ProblemSolvingĀ #Algorithms #365dayschallenge
To view or add a comment, sign in
-
-
LeetCode POTD š«: Description: AĀ happy stringĀ is a string that: -> consists only of letters of the setĀ ['a', 'b', 'c']. -> s[i] != s[i + 1]Ā for all values ofĀ iĀ fromĀ 1Ā toĀ s.length - 1Ā (string is 1-indexed). For example, stringsĀ "abc", "ac", "b"Ā andĀ "abcbabcbcb"Ā are all happy strings and stringsĀ "aa", "baa"Ā andĀ "ababbc"Ā are not happy strings. Given two integersĀ nĀ andĀ k, consider a list of all happy strings of lengthĀ nĀ sorted in lexicographical order. ReturnĀ the kth stringĀ of this list or return anĀ empty stringĀ if there are less thanĀ kĀ happy strings of lengthĀ n. Here's my solution: https://lnkd.in/gEe77wac #Python #DSA #Leetcode #DailyChallenge #Recursion
To view or add a comment, sign in
-
-
Ask your agent to delete a database. And it will. No questions asked. That's terrifying. Two gates fix it. One checks the input before the agent runs. One checks the output before you see it. Each gate is a list of functions. Adding a rule? One more line. "drop all tables" ā blocked. Before it even starts. Answer mentions a password ā redacted. Before you see it. Same agent. Now with boundaries. Checkout the video. Day 7 of 9. https://lnkd.in/gQZQWy4D #AIAgents #AISafety #BuildInPublic #Python
To view or add a comment, sign in
-
ā Day 8 of #DSAPrep > Problem: Convert Number to Hexadecimal > Platform: LeetCode > Concept: Base Conversion (Decimal ā Hexadecimal) Converted an integer to its hexadecimal representation without using built-in conversion functions. > Key points: - Used modulo 16 to extract digits - Mapped values 10ā15 to 'a'ā'f' - Handled negative numbers using 32-bit twoās complement logic - Reversed the result at the end > Time Complexity: O(logāā n) > Space Complexity: O(logāā n) Example: 28 ā 1c #DSAPrep #Algorithms #Python #NumberSystem #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Ask Claude to refactor a module. It reads related files. Checks tests. Updates imports. Things you never asked for. How does it decide what to do next? Give it a tool called schedule_followup(). It looks like any other tool. But the side effect is ā a new task enters the queue. The agent doesn't know it's planning. It's just calling a tool. Sound familiar? (That's lesson 6 all over again.) An outer loop drains the queue. A budget stops it from running forever. That's CrewAI delegation in 10 lines. Checkout the video. Day 8 of 9. One more to go. https://lnkd.in/g-YiAgtE #AIAgents #BuildInPublic #Python #LLM
To view or add a comment, sign in
-
Understanding how data structures behave is crucial for writing reliable and scalable Python code. In my latest article, I explore the real difference between Lists and Tuples in Python and why choosing the right one can impact system stability, performance, and trust in real-world applications. From flexibility to stability, this article explains when data should evolve and when it must remain unchanged. Read the full article here: https://lnkd.in/gvQahst3 #Python #DataScience #Programming #Coding #PythonProgramming #SoftwareEngineering #TechLearning #Developers #DataEngineering #Analytics #MachineLearning #AI #TechCommunity #LearnToCode #CareerGrowth
To view or add a comment, sign in
-
We started with a single function. Added tools. Made it loop. Gave it memory. Tracked state. Persisted facts. Added guardrails. Let it plan. Eight lessons. All building on each other. Now they compose. 60 lines of Python. Remember my name is Alice, then add ten and five. ā saves to memory, runs the tool, returns fifteen. New session. What is my name? ā Alice. From memory. Delete the database. ā Blocked. Before it even runs. Same sixty lines. Every feature you've built. No LangChain. No CrewAI. No AutoGen. Just json, pyfetch, and one HTTP call. This is the same architecture as every agent framework out there. The difference: you can read every line. The entire series is free. Runs in your browser. No setup. tinyagents.dev Day 9 of 9. Series complete. https://lnkd.in/gwmgUzex #AIAgents #BuildInPublic #Python #LLM #OpenSource
To view or add a comment, sign in
-
LeetCode POTD š«: Description: Write an API that generates fancy sequences using theĀ append,Ā addAll, andĀ multAllĀ operations. Implement theĀ FancyĀ class: - Fancy()Ā Initializes the object with an empty sequence. - void append(val)Ā Appends an integerĀ valĀ to the end of the sequence. - void addAll(inc)Ā Increments all existing values in the sequence by an integerĀ inc. - void multAll(m)Ā Multiplies all existing values in the sequence by an integerĀ m. - int getIndex(idx)Ā Gets the current value at indexĀ idxĀ (0-indexed) of the sequenceĀ moduloĀ 10^9 + 7. If the index is greater or equal than the length of the sequence, returnĀ -1. Here's my solution: https://lnkd.in/gAbFX8KX #Python #DSA #Leetcode #DailyChallegne #Hard
To view or add a comment, sign in
-
-
ā Day 10 of #DSAPrep > Problem: Best Time to Buy and Sell Stock > Platform: LeetCode > Concept: Greedy + Array Traversal Implemented an optimal solution to find the maximum profit from stock prices by tracking the minimum buying price and updating the maximum profit while iterating through the array. > Key Idea: - Keep track of the lowest price seen so far - Calculate potential profit at each step - Update the maximum profit if a better one is found > Time Complexity: O(n) > Space Complexity: O(1) #DSAPrep #Algorithms #Python #GreedyAlgorithm #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
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