Progreso Diario de LeetCode Día 13

Guía de hashing y detección de ciclos con dos punteros: Longest Palindrome y Linked List Cycle. Explicaciones, complejidad O(n) y ejemplos en Python y C++.

30 ago 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Problemas resueltos #409 Longest Palindrome #141 Linked List Cycle

Resumen del día 14 Hashing y detección de ciclos con dos punteros. Hoy trabajé en conteo de frecuencias para maximizar la longitud de un palíndromo y en detección de ciclos en listas enlazadas usando punteros de velocidad distinta.

Qué aprendí Para Longest Palindrome basta contar frecuencias de caracteres: cada par contribuye al palíndromo y si existe algún conteo impar se puede colocar exactamente un carácter impar en el centro. Para Linked List Cycle el clásico algoritmo de Floyd tortuga y liebre funciona eficientemente: dos punteros con velocidades diferentes acabarán encontrándose si existe un ciclo. Ambos problemas subrayan el seguimiento simple de estado: conteos de frecuencia para caracteres y posiciones relativas de punteros para detectar ciclos.

#409 Longest Palindrome explicación Idea principal: sumar los pares completos de cada carácter y añadir uno si hay al menos un conteo impar. Complejidad temporal O(n) y espacio O(1) si consideramos un alfabeto limitado. Implementación conceptual en Python: from collections import Counter cnt = Counter(s) pairs = sum(v // 2 for v in cnt.values()) return pairs * 2 + (1 if any(v % 2 for v in cnt.values()) else 0) Implementación conceptual en C++: usar unordered_map para contar, acumular length con (count / 2) * 2 y marcar si existe un impar para añadir uno al final.

Por qué funciona Los conteos pares se usan completamente como pares simétricos en el palíndromo y solo se puede situar un carácter impar en el centro, por eso la fórmula anterior es correcta y óptima en tiempo.

#141 Linked List Cycle explicación Idea principal: el algoritmo de Floyd usa dos punteros, slow y fast, que avanzan a pasos distintos. Si existe un ciclo se encontrarán; si no, fast llegará al final. Complejidad temporal O(n) y espacio O(1). Implementación conceptual en Python: si head es None o head.next es None return False slow = head fast = head while fast and fast.next: slow = slow.next fast = fast.next.next if slow == fast: return True return False Implementación conceptual en C++ sigue la misma lógica usando punteros ListNode.

Por qué funciona Si hay un ciclo la diferencia en velocidades reduce la distancia entre los punteros hasta cero y se produce el encuentro; si no hay ciclo el puntero rápido alcanza null y se devuelve falso.

Logros Implementaciones en Python y C++ para Longest Palindrome y Linked List Cycle. Visualizaciones y pruebas locales completadas.

Recap de complejidad Longest Palindrome: tiempo lineal en la longitud de la cadena y espacio constante para alfabeto limitado. Linked List Cycle: tiempo lineal en la longitud de la lista y espacio constante.

Sobre Q2BSTUDIO Q2BSTUDIO es una empresa de desarrollo de software especializada en aplicaciones a medida y software a medida. Ofrecemos soluciones avanzadas en inteligencia artificial e ia para empresas, diseño de agentes IA y desarrollos a medida que integran servicios cloud aws y azure. Nuestros servicios incluyen ciberseguridad, consultoría en servicios inteligencia de negocio y visualización con power bi, integración de modelos de inteligencia artificial y desarrollo de aplicaciones móviles y web. Somos especialistas en crear soluciones personalizadas que combinan inteligencia artificial, agentes IA y analítica con power bi para mejorar la toma de decisiones empresariales. Si buscas software a medida, aplicaciones a medida, servicios cloud aws y azure, ciberseguridad o proyectos de inteligencia artificial para tu empresa, Q2BSTUDIO puede ayudar a diseñar e implementar la solución adecuada.

Únete al viaje Estoy documentando problemas diariamente en Python y C++ cubriendo hashing, punteros, recursión y programación dinámica. Sigue la serie para ver soluciones paso a paso y ejemplos aplicables. Enlaces útiles: LinkedIn https://www.linkedin.com/in/ertugrul-mutlu GitHub https://github.com/Ertugrulmutlu/leetcode-series

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