conversations
listlengths
3
3
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the maximum product of two integers in an array." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef find_...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function that takes a positive integer and returns the number of digits in its factorial." }, { "from": "gpt", "value": "Here is the code to solve this proble...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the partitions of a string such that every substring of the partition is a palindrome.\n\nA palindrome is a string that reads the same backward as forward.\n\nR...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the number of possible binary search trees (BSTs) that can be formed with 'n' unique nodes." }, { "from": "gpt", "value": "Here is the code t...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the last index of a given value in a list." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef last_index(...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function that takes a list of integers and returns a new list where each element is the maximum value found up to that point in the original list." }, { "from": "...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the largest number in a list of integers that is also a Fibonacci number. If there is no Fibonacci number in the list, return -1." }, { "from": "...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to calculate the area of a rectangle given its length and width." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef rect...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function that takes a positive integer and returns the product of all the digits in the number." }, { "from": "gpt", "value": "Here is the code to solve this ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to check if a given list of numbers is in ascending order or not." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\n...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string \"\"." }, { "from": "gpt", ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Create a function that takes a list of integers and returns a dictionary where the keys are the original numbers and the values are their corresponding factorial values. If a number is ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to reverse the order of words in a given sentence." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef reverse_words_orde...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to get the factors of a given number." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef factors(n):\n result ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the number of steps required to make all the elements of an array equal by performing the following operation: in one step, you can choose any non-zero e...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to check if a given list of intervals can be attended without any overlaps. Each interval is represented as a list of two integers where the first integer is the...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to check if a given list has consecutive integers." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef chkConsecut...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the smallest substring that contains all the characters of the given string." }, { "from": "gpt", "value": "Here is the code to solve this pr...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to count the number of times a target value appears in a binary search tree (BST)." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n`...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to calculate the number of ways an integer can be expressed as a sum of consecutive integers." }, { "from": "gpt", "value": "Here is the code to solve this ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the sum of individual elements in a binary list using list comprehension." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n``...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the number of distinct palindromic substrings in a given string.\n\nA palindromic string is a string that reads the same backward as forward." }, { "fro...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to check whether a given list of integers is an arithmetic array or not. An arithmetic array is a sequence of numbers such that the difference of any two successive mem...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function that takes two lists as parameters and returns a list of common elements between the two lists. The returned list should not contain any duplicates." }, { "from...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the largest number in a list of integers. The function should handle both positive and negative numbers and return None if the list is empty." }, { "fro...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function that takes a string of parentheses and returns the minimum number of parentheses that need to be removed to make the string valid. A valid string of parentheses ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the sum of the two largest numbers in a given list of integers." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```py...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function that will return a list of prime numbers up to a given limit using the Sieve of Eratosthenes algorithm." }, { "from": "gpt", "value": "Here is the code to s...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function that converts a given number into a specified base and returns the result as a string. The base can be 2, 8, 10, or 16. If the base is not one of these, the func...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a Python function to determine if a string is a palindrome and contains only lowercase letters. A palindrome is a word, phrase, number, or other sequence of characters that reads ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the number of distinct products obtained by multiplying two numbers from different indices in the array.\n\nFor example, given the array [1, 2, 3, 4], th...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to calculate the Fibonacci number at a given position using recursion." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```pyt...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Create a python function to find the largest subarray with an equal number of 0's and 1's in a binary array." }, { "from": "gpt", "value": "Here is the code to solve this pr...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function that takes a list of integers and returns a new list with each element squared." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```p...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to check if a given string is a valid password. A valid password must satisfy the following criteria:\n1. It must be at least 8 characters long.\n2. It must cont...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the number of nice words in a given text. A word is considered nice if it contains at least one pair of two consecutive letters that appears at least twice in t...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the number of unreachable pairs in a given undirected graph. The graph is represented using a list of edges." }, { "from": "gpt", "value": "H...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the smallest number in a list which has all its prime factors less than or equal to 3." }, { "from": "gpt", "value": "Here is the code to solve this...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to segregate even and odd numbers in a given list. The function should return two lists, one with all the even numbers and one with all the odd numbers." }, ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to reverse the digits of a given number and check if it is a palindrome." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\n...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Implement a function that takes in a string representing a large number and a multiplier, and returns the product as a string. This function should handle large numbers that exceed the ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to check whether a given number is a power of two." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef is_Power_of...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to simulate a stack operation by validating if two arrays represent the push and pop sequence of a stack correctly." }, { "from": "gpt", "value": "Here is t...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the shortest subarray with a given sum." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef find_min_length_subar...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to determine if a string can be segmented into space-separated words in the dictionary." }, { "from": "gpt", "value": "Here is the code to solve this proble...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function that takes a string as input and returns a new string with the first letter of each word capitalized." }, { "from": "gpt", "value": "Here is the code...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the minimum number of intervals needed to remove to make the remaining intervals non-overlapping.\n\nFunction signature: `def min_intervals_to_remove(intervals:...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to reverse the order of words in a given sentence." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef sentence_re...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the relative ranks of the contestants in a competition. Given a list of integers representing the scores of N contestants, return a list of strings representing...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function that takes a list of integers and returns a new list with each element's binary representation as a string, but with any leading zeros removed. If an integer is zero, i...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the number of ways to express a given number as a sum of consecutive positive integers." }, { "from": "gpt", "value": "Here is the code to so...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the common elements between two lists." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef common_Elements...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the lowest number in a given list of integers." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef find_lowest(ar...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the maximum number in an array of integers using recursion." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef m...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the total number of ways to reach the top of a staircase, given the ability to climb either 1 or 2 steps at a time." }, { "from": "gpt", "val...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to convert a given string to uppercase without using built-in string methods." }, { "from": "gpt", "value": "Here is the code to solve this problem:\...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to check if a number is a confusing number. A confusing number is a number that, when rotated 180 degrees, becomes a different number, and each digit remains valid afte...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function that takes a list of numbers and returns a list of tuples where each tuple contains the number and its square." }, { "from": "gpt", "value": "Here is...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Create a python function that finds the smallest repeated substring in a string. If no such substring exists, return -1." }, { "from": "gpt", "value": "Here is the code to s...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to return the number of lattice paths from the top-left corner to the bottom-right corner of a grid with a given size. You can only move either down or right at any poi...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Create a python function that takes a string and shifts all the characters three places to the right, wrapping around the end. This is commonly known as a Caesar Cipher with a shift of ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to compute the running median of a sequence of numbers. That is, given a stream of numbers, maintain the median of the list so far for each new element." }, { "...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a Python function that finds the largest and smallest numbers in a list of integers that have the same parity (both even or both odd). If such numbers do not exist, return None fo...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to check if a given number is a perfect number or not. A perfect number is a positive integer that is equal to the sum of its proper divisors, excluding itself."...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the longest common prefix string amongst an array of strings.\nIf there is no common prefix, return an empty string \"\"." }, { "from": "gpt", ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the length of the longest substring without repeating characters in a given string." }, { "from": "gpt", "value": "Here is the code to solve this pr...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to remove duplicates from a sorted linked list. The function should return the head of the modified linked list." }, { "from": "gpt", "value": "Here is the ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the minimum number of swaps required to sort an array." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef min_sw...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function that checks if a given list of integers is sorted in non-decreasing order, and if not, sorts it in non-decreasing order and returns the sorted list." }, { "from...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the list with maximum sum of elements from a list of lists." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef m...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the next perfect square of a given number. If the given number is already a perfect square, return the next perfect square. If the next perfect square does not ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to return the path of the minimum cost from the top left corner to the bottom right corner of a given grid. You can only move either down or right at any point in time....
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function that takes a string as input and returns a new string where all the digits in the string are replaced with the word \"number\" if they are less than 5, or the word \"di...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to check if a string can be transformed into a palindrome by replacing at most one character.\n\nA palindrome is a word, phrase, number, or other sequence of characters...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the smallest set of vertices in a directed graph such that every node in the graph is reachable from at least one of the vertices in the set." }, { ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to check whether a number is a prime number or not." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef prime_number(n):\...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to calculate the power of a number using recursion." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef pow(base, ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the starting index where a subsequence can be found in a list, or return -1 if the subsequence is not present." }, { "from": "gpt", "value": ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the maximum number of toys that can be purchased with a given amount of money. Each toy has a price, and you can buy as many toys of each type as you want. The ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function that takes in a string and returns a list of words in the string. The function should split the string by whitespace and remove any leading or trailing punctuation mark...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the most frequent items in a list along with their frequencies." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\nf...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function that takes a list of numbers as input and returns a list of tuples, where each tuple contains two elements: the number itself and its square root. Note that the ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to check if a given string of moves is circular. A move is circular if the number of 'U' (up) moves equals the number of 'D' (down) moves, and the number of 'L' ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to determine if a given grid can be covered with 2 x 1 dominoes.\n\nA grid can be covered with dominoes if:\n- The grid's width and height are even.\n- Each cell of the...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function that takes a list of strings and returns the length of the longest string in the list." }, { "from": "gpt", "value": "Here is the code to solve this ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to find the intersection of two lists of intervals. The intervals in the list are represented by a pair of integers [start, end]. The intersection of two intervals is a...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the smallest common multiple of two positive integers." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the maximum product of three numbers in a given list of integers." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function to calculate the average of the digits in a given string that are divisible by 3." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n``...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function that takes a list of integers as input and returns the largest product that can be obtained by multiplying any three integers from the list." }, { "from"...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function that takes a string and returns the number of occurrences of a specific character in that string." }, { "from": "gpt", "value": "Here is the code to solve t...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the nth Fibonacci number using dynamic programming." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef fi...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the smallest and largest elements in a given array." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef fi...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a Python function that converts a given temperature in Celsius to Fahrenheit. The formula for converting Celsius to Fahrenheit is: F = (C * 9/5) + 32" }, { "from": "gpt", ...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the index of the first occurrence of a substring within a string. If the substring is not found, return -1." }, { "from": "gpt", "value": "He...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function that counts the number of capital letters in a given string." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef c...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to find the number of continuous subarrays whose sum equals to k." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\n...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function to check if a given string is a valid IPv4 address." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```python\ndef check_IPv4...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a function that takes a list of integers as input and returns a new list with all the elements reversed and incremented by 1." }, { "from": "gpt", "value": "Here is th...
[ { "from": "system", "value": "You are an assistant that responds to the user." }, { "from": "human", "value": "Write a python function that converts the first letter of each word in a sentence to uppercase." }, { "from": "gpt", "value": "Here is the code to solve this problem:\n```py...