Sum Of Two Linked Lists
Function Name: sumOfLinkedLists
Description
Write a function 'sumOfLinkedLists' that takes two arguments representing the heads of two non-empty linked lists, each of which contains non-negative integers. The digits are stored in reverse order, with each of their nodes containing a single digit. Add the two numbers and return the sum as a linked list in the same reversed format.
The function should create a new linked list that represents the sum of the numbers, with nodes containing single digits and the linked list still reversed.
You can assume the two linked lists do not contain any leading zeros, except for the number 0 itself.
Requirements
- Do not use any built-in linked list libraries or convert the linked list to another data structure.
- You should define a linked list node class/struct with at least two attributes: an integer value and a reference to the next node.
- The time complexity of your solution should be O(max(n, m)), where n and m are the lengths of the two linked lists.
Examples
Suppose we have two linked lists 3->1->5 (which represents 513) and 5->9->2 (which represents 295).After calling your function with these lists, we should get the head of a new linked list 8->0->8 (which represents 808).Function call: sumOfLinkedLists(list1.head, list2.head)Output: A new linked list with head node value 8 and following the nodes with values 0 and 8.
Links
Stock Spanner
Mon Sep 30 2024
Write a function to calculate the span of stock’s price on a given list of days. The span of the stock’s price today is defined as the maximum number of consecutive days (starting from today and going backward) for which the price of the stock was less than or equal to today's price.The function should take an array of integers representing the stock prices and return an array of integers representing the span of each stock price.
Simple Database Query Processor
Wed Oct 02 2024
Write a function that simulates a simple database query processor. The function should accept two parameters: a list of dictionaries representing 'rows' in a database table, and a query string representing a simple filtering condition. Each dictionary in the list corresponds to a database row, where the key-value pairs of the dictionary correspond to column names and cell data, respectively.The query string will be a simple conditional statement in the format 'column_name == value', where 'column_name' is a key in the dictionaries and 'value' is the value to match. The function should return a list of dictionaries where the condition is true.For simplicity, assume that all column values are strings and that the queries use '==' for equality checks only. Handle the case where the query string is malformed or columns do not exist—return an empty list in these situations.