Manafall Daily Quest

LinkedListCycleDetector

Function Name: hasCycle

Description

Write a function named 'hasCycle' that takes the head of a singly linked list as its single parameter.

The function should determine whether the linked list contains a cycle, which is a situation where nodes in the list form a loop.

A singly linked list is said to have a cycle if, by continuously following the next pointers, a node is encountered that has already been visited.

The function should return a boolean value: true if the list contains a cycle, and false otherwise.

Requirements

  • The linked list node structure should be defined within the code, containing at least a 'value' and a 'next' attribute.
  • The function must not modify the original linked list.
  • Optimize the function for linear time complexity and constant space complexity.
  • The linked list may contain any number of nodes, or it may be empty.

Examples

Given a linked list head -> 1 -> 2 -> 3 -> 4 -> 2 (same 2 as earlier), the function should return true, since the list contains a cycle.Given a linked list head -> 1 -> 2 -> 3 -> null, the function should return false, as the list does not contain a cycle.

Links

https://en.wikipedia.org/wiki/Cycle_detectionhttps://www.geeksforgeeks.org/detect-loop-in-a-linked-list/

Temperature Converter

Mon Nov 04 2024

Write a function that converts temperatures between different units.The function will take two parameters: the value to convert (a floating-point number) and the unit it's converting from ('C', 'F', or 'K' representing Celsius, Fahrenheit, and Kelvin, respectively).The function should return an object with the keys 'C', 'F', and 'K', representing the value of the temperature in Celsius, Fahrenheit, and Kelvin.Conversions should be accurate to at least one decimal place.

Prev Quest

Balanced Parentheses Checker

Wed Nov 06 2024

Write a function that takes a string containing only parentheses characters '(', ')', '{', '}', '[' and ']', and determines if the input string is valid.An input string is valid if:- Open brackets are closed by the same type of brackets.- Open brackets are closed in the correct order.No extra characters are allowed in the input string.

Next Quest