Progreso Diario de LeetCode – Día 19

Diario de LeetCode: domina sliding window con Max Consecutive Ones III y Find All Anagrams in a String en Python y C++, expansión y contracción de ventana y contadores de frecuencia, con complejidad O(n) y aplicaciones en desarrollo de software e IA.

8 sept 2025 • 4 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Problemas resueltos: #1004 Max Consecutive Ones III y #438 Find All Anagrams in a String

Progreso Diario de LeetCode – Día 19. Continuo mi serie diaria trabajando la tecnica sliding window con dos retos clasicos: maximizar la racha de unos permitiendo hasta k flips y encontrar todos los indices iniciales de anagramas en una cadena. Ambos refuerzan el patron crecer la ventana, encoger cuando es invalida y actualizar el resultado.

Lo que aprendi: 1 La ventana se expande con el puntero derecho y se contrae solo cuando hay mas de k ceros para mantener siempre una ventana valida. 2 Para los anagramas, mantener contadores de frecuencia de p y de la ventana de s permite detectar coincidencias en tiempo lineal. 3 El template de sliding window es universal y reusable.

#1004 Max Consecutive Ones III en Python

class Solution: def longestOnes(self, nums: List[int], k: int) -> int: n, right = len(nums), 0 left = 0 temp_k = k max_temp = 0 while right < n: if nums[right] == 0: temp_k -= 1 while temp_k < 0: if nums[left] == 0: temp_k += 1 left += 1 max_temp = max(max_temp, right - left + 1) right += 1 return max_temp

#1004 Max Consecutive Ones III en C plus plus

class Solution { public: int longestOnes(vector<int>& nums, int k) { int n = nums.size(); int left = 0, right = 0; int temp_k = k; int max_temp = 0; while (right < n) { if (nums[right] == 0) { temp_k--; } while (temp_k < 0) { if (nums[left] == 0) { temp_k++; } left++; } max_temp = max(max_temp, right - left + 1); right++; } return max_temp; } };

Complejidad: Tiempo O n y Espacio O 1.

#438 Find All Anagrams in a String en Python

class Solution: def findAnagrams(self, s: str, p: str) -> List[int]: n, right = len(s), len(p) if right > n: return [] need = Counter(p) window = Counter(s[:right]) start_index = [] if need == window: start_index.append(0) for i in range(right, n): window[s[i]] += 1 left_c = s[i - right] window[left_c] -= 1 if window[left_c] == 0: del window[left_c] if window == need: start_index.append(i - right + 1) return start_index

#438 Find All Anagrams in a String en C plus plus

class Solution { public: vector<int> findAnagrams(string s, string p) { int n = s.size(); int m = p.size(); if (m > n) return {}; vector<int> need(26, 0), window(26, 0); for (char c : p) need[c - 97]++; vector<int> res; int left = 0, right = 0; while (right < n) { window[s[right] - 97]++; right++; if (right - left == m) { if (window == need) res.push_back(left); window[s[left] - 97]--; left++; } } return res; } };

Complejidad: Tiempo O n y Espacio O 26 aproximado a O 1.

Logros del dia: implemente la expansion y contraccion de ventana para maximizar unos con flips y detecte indices de anagramas mediante matching de frecuencias en Python y C plus plus.

Resumen de complejidad: Max Consecutive Ones III O n tiempo y O 1 espacio. Find All Anagrams in a String O n tiempo y O 1 espacio.

Sobre Q2BSTUDIO: en Q2BSTUDIO desarrollamos software a medida y aplicaciones a medida con calidad de producto y velocidad de startup, apoyados por inteligencia artificial y agentes IA para automatizar procesos y acelerar la entrega de valor. Si buscas crear una plataforma solida y escalable, descubre nuestro servicio de desarrollo de aplicaciones y software a medida para web y movil. Ademas, integramos modelos de ia para empresas con auditorias de ciberseguridad, servicios cloud aws y azure, y servicios inteligencia de negocio con power bi. Si tu roadmap tecnico incluye modelos generativos, orquestacion con agentes IA y despliegues seguros, consulta tambien nuestra oferta de inteligencia artificial aplicada a negocio.

Como encaja este aprendizaje con Q2BSTUDIO: la tecnica sliding window es un ejemplo de pensamiento algoritimico que aplicamos en proyectos reales de software a medida, desde analisis de flujos en tiempo real hasta deteccion de patrones en datos. Combinamos buenas practicas de ingenieria con pipelines de datos y seguridad por diseno para que tus soluciones en cloud aws o azure sean eficientes, seguras y medibles con power bi.

Seguire publicando soluciones diarias en Python y C plus plus cubriendo arrays, sliding window, linked lists y arboles mientras incorporo patrones que usamos en proyectos de clientes de alto impacto. Si te interesa acelerar tu producto mediante ia para empresas, ciberseguridad y automatizacion, hablemos.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat