messages listlengths 2 2 | source stringclasses 1
value |
|---|---|
[
{
"content": "Implement a binary search on the given array, but instead of searching for a specific value, search for the index of the smallest element in the array that is greater than a given target value. Return -1 if there is no such element.\nArray = [1, 4, 5, 6, 7, 9]\nTarget value = 3",
"role": "user... | codefeedback |
[
{
"content": "Suggest a Python code to parse an XML document and extract specific data elements based on user input. Additionally, handle any potential errors or exceptions that may occur during the parsing process.",
"role": "user"
},
{
"content": "Here's an example Python code that uses the `xml.e... | codefeedback |
[
{
"content": "In Python, write code to identify whether a given string contains only numeric values, but the numeric values must be in scientific notation with an exponent.",
"role": "user"
},
{
"content": "You can use a regular expression to check whether a string contains only numeric values in sc... | codefeedback |
[
{
"content": "Implement a bubble sort algorithm in a programming language of your choice to sort an array of integers in ascending order. The algorithm should have a time complexity of O(n^2) and should not use any built-in sorting functions or libraries.",
"role": "user"
},
{
"content": "Sure! Here... | codefeedback |
[
{
"content": "Create a class in Python that implements a stack and includes the following methods:\n\n1. `push(item)`: Add an item to the top of the stack.\n2. `pop()`: Remove and return the top item from the stack.\n3. `peek()`: Return the top item from the stack without removing it.\n4. `is_empty()`: Check if... | codefeedback |
[
{
"content": "Create a Python program to extract all unique words from a given sentence, while also counting the frequency of each word. This sentence may contain punctuation marks and may have words in different cases (uppercase and lowercase) that should be considered as the same word. Additionally, exclude c... | codefeedback |
[
{
"content": "Suggest a sorting algorithm to sort the following array in descending order. The algorithm should have a time complexity of O(nlogn) and must be implemented using recursion. Additionally, the sorted array should be stored in a new array and the original array should remain unchanged. arr = [17, 21... | codefeedback |
[
{
"content": "Generate a 3x3 matrix of random real numbers in the range of -10.0 to 10.0. Sort the matrix in ascending order and calculate the sum of the numbers in the first row. Finally, print the sorted matrix and the sum of the first row.",
"role": "user"
},
{
"content": "Here is a Python code t... | codefeedback |
[
{
"content": "Create a Python function that takes in a string as input and returns a dictionary where the keys are the unique characters in the string and the values are lists containing the indices of each occurrence of the character in the string.\n\nExample:\nInput: \"hello\"\nOutput: {'h': [0], 'e': [1], 'l... | codefeedback |
[
{
"content": "Generate a 10-element tuple of random prime numbers between 50 and 100 using Python.",
"role": "user"
},
{
"content": "Here is a possible solution using the random and sympy libraries in Python:\n\n```python\nimport random\nfrom sympy import isprime\n\nprimes = []\nwhile len(primes) < ... | codefeedback |
[
{
"content": "Generate an array of prime numbers up to and including the number ",
"role": "user"
},
{
"content": "Here is an example of generating an array of prime numbers up to and including a given number:\n\n```python\ndef is_prime(n):\n if n < 2:\n return False\n for i in range(2,... | codefeedback |
[
{
"content": "Write a function in Python to check if two strings are an anagram or not, but without using any built-in string manipulation methods or libraries.",
"role": "user"
},
{
"content": "Here's a Python function that checks if two strings are anagrams without using any built-in string manipu... | codefeedback |
[
{
"content": "Implement a doubly linked list in Python.",
"role": "user"
},
{
"content": "Sure! Here's an implementation of a doubly linked list in Python:\n\n```python\nclass Node:\n def __init__(self, data):\n self.data = data\n self.prev = None\n self.next = None\n\n\nclas... | codefeedback |
[
{
"content": "Implement a function that validates and formats the following JSON data based on a specific schema:\n{\n \"name\": \"John\",\n \"age\": 20,\n \"address\": {\n \"street\": \"123 Main St\",\n \"city\": \"New York\",\n \"state\": \"NY\",\n \"country\": \"USA\"\n ... | codefeedback |
[
{
"content": "Create a class to represent a two-dimensional vector. Implement the following methods:\n\n1. `__init__(self, x: float, y: float)`: Initialize the vector with the given x and y coordinates.\n\n2. `get_x(self) -> float`: Return the x-coordinate of the vector.\n\n3. `get_y(self) -> float`: Return the... | codefeedback |
[
{
"content": "Write a recursive function that calculates the factorial of a given number in Python. The function should handle negative numbers as well.",
"role": "user"
},
{
"content": "Here is a recursive function in Python that calculates the factorial of a given number, handling negative numbers... | codefeedback |
[
{
"content": "Classify a collection of articles as spam or ham.\nGiven a collection of articles, you are required to classify each article as spam or ham. The input is a list of strings where each string represents an article. Your task is to implement a function that takes in this list and returns a list of cl... | codefeedback |
[
{
"content": "Suggest an algorithm for sorting a list of integers in descending order. The algorithm should have a time complexity of O(n^2) and should not use any built-in sorting functions or libraries.",
"role": "user"
},
{
"content": "One algorithm that meets the requirements is the Bubble Sort ... | codefeedback |
[
{
"content": "Count the number of vowels in a sentence, but only consider vowels that occur after a consonant and before another consonant. Ignore any vowels that occur at the beginning or end of a word.\n\nExample input: \"The quick brown fox jumps over the lazy dog\"\nExpected output: 2\n\nExample input: \"Sh... | codefeedback |
[
{
"content": "Write a loop in Python to print all the numbers from 0 to 10, but skip printing the number 5 and only print even numbers.",
"role": "user"
},
{
"content": "Here's an example of a loop in Python that prints all the numbers from 0 to 10, skipping the number 5 and only printing even numbe... | codefeedback |
[
{
"content": "Write a function to check if a given binary tree is a valid binary search tree, where the time complexity should be O(n) and the space complexity should be O(1).",
"role": "user"
},
{
"content": "To check if a binary tree is a valid binary search tree, we need to compare each node with... | codefeedback |
[
{
"content": "Return a subset of a given array where the sum of all elements in the subset is the maximum possible value, given that the subset size is exactly K.\narr = [3, 6, 2, 5, 7, 4], K = 3",
"role": "user"
},
{
"content": "To find a subset of size K with the maximum possible sum, we can use t... | codefeedback |
[
{
"content": "Build a Python program to transform a string in a dictionary.\nString: \" John, 26, Movie Watch, Jane, 31, Book Reader, Charlotte, 25, Music Listener\"\n\nRequirements:\n1. The input string will always be in the format \"Name, Age, Hobby, Name, Age, Hobby, Name, Age, Hobby, ...\".\n2. The names ca... | codefeedback |
[
{
"content": "Create a switch statement for the following string:\ninput = “cat”, and add an additional requirement that the switch statement should also handle the following cases: \"dog\", \"mouse\", and \"rabbit\".",
"role": "user"
},
{
"content": "Here's an example of a switch statement in Pytho... | codefeedback |
[
{
"content": "Write a function that takes a string as an argument, reverses the words in the string, and returns the reversed string. Each word in the string should maintain its original order, but the order of the words in the string should be reversed.",
"role": "user"
},
{
"content": "Here is a P... | codefeedback |
[
{
"content": "Create a function that outputs the minimum and maximum of a list of numbers, but without using built-in functions like min() and max(). The list will always have at least 5 numbers and may contain duplicates.",
"role": "user"
},
{
"content": "Here is a Python function that finds the mi... | codefeedback |
[
{
"content": "Construct a program to parse a JSON array with the additional requirement that the program should calculate the average age of the individuals in the array. The program should also display the name of the oldest person in the array. Additionally, the program should validate that each object in the... | codefeedback |
[
{
"content": "Generate a code snippet to find the highest common factor of two given numbers using only bitwise operators and without using any arithmetic operators.",
"role": "user"
},
{
"content": "To find the highest common factor of two given numbers using only bitwise operators and without usin... | codefeedback |
[
{
"content": "Generate a code snippet to convert a given string to uppercase without using any built-in string manipulation functions or methods.",
"role": "user"
},
{
"content": "Here is a code snippet in Python to convert a given string to uppercase without using any built-in string manipulation f... | codefeedback |
[
{
"content": "What is the purpose of a try-catch block in Python when handling exceptions raised by asynchronous functions that use coroutines and generators?",
"role": "user"
},
{
"content": "The purpose of a try-catch block in Python when handling exceptions raised by asynchronous functions that u... | codefeedback |
[
{
"content": "Write a Python function to compute the factorial of an integer, with the additional requirement that the function should handle negative integers and return None for negative inputs.",
"role": "user"
},
{
"content": "Here is a Python function that computes the factorial of an integer w... | codefeedback |
[
{
"content": "Given a list of people's names and their corresponding birth dates, print the difference in time from each person's birthday to the current time. The list will be in the following format:\npeople = [(\"John\", datetime.datetime(1990, 5, 10, 8, 0, 0)), \n (\"Emily\", datetime.datetime(1985... | codefeedback |
[
{
"content": "You are given two strings. Write a function that checks whether the two strings are an anagram or not. The function should also handle cases where the strings contain special characters, whitespace, and numbers.",
"role": "user"
},
{
"content": "Here's a Python function that checks whe... | codefeedback |
[
{
"content": "You are given a list of strings. Write a program to check if the given list is a palindrome or not. A palindrome list is defined as a list where each string in the list is a palindrome.",
"role": "user"
},
{
"content": "To solve this problem, we can iterate through the given list of st... | codefeedback |
[
{
"content": "You are given a string of symbols. Write a program to remove all the symbols and get a valid text string. If there are multiple valid text strings, choose the one with the highest frequency of vowels. If there are no vowels, return an empty string. If there are multiple valid text strings with the... | codefeedback |
[
{
"content": "Write a function in Python for calculating the area of a circle, but you are not allowed to use the built-in `math` module or any other library that provides a method for calculating the value of pi.",
"role": "user"
},
{
"content": "To calculate the area of a circle without using the ... | codefeedback |
[
{
"content": "Develop an efficient algorithm for sorting a given list in ascending order. Your algorithm should have a time complexity of O(nlogn) and should not use any built-in sorting functions or libraries. Additionally, the algorithm should be implemented in a way that it can handle duplicate elements in t... | codefeedback |
[
{
"content": "Create a list containing a given number of random numbers, where each number must be unique and within a specified range.",
"role": "user"
},
{
"content": "To create a list containing a given number of random numbers, where each number must be unique and within a specified range, you c... | codefeedback |
[
{
"content": "Create a function in Python that returns all distinct permutations of a string, where a distinct permutation is defined as a permutation that is unique among all permutations of the string.",
"role": "user"
},
{
"content": "To generate all distinct permutations of a string in Python, y... | codefeedback |
[
{
"content": "Given a character sequence, find the longest palindromic substring. The length of the sequence will not exceed 1000 characters.",
"role": "user"
},
{
"content": "To find the longest palindromic substring in a given character sequence, we can use the following approach:\n\n1. Initialize... | codefeedback |
[
{
"content": "Create an array of size n filled with the string \"hello\". Additionally, convert all vowels in the string to uppercase and all consonants to lowercase.",
"role": "user"
},
{
"content": "Here's a code snippet in Python that creates an array of size n, fills it with the string \"hello\"... | codefeedback |
[
{
"content": "Find all palindromic substrings from a given string.",
"role": "user"
},
{
"content": "To find all palindromic substrings from a given string, we can use the following steps:\n\n1. Initialize an empty list to store all palindromic substrings.\n2. Iterate through each character in the s... | codefeedback |
[
{
"content": "Explain the term \"backtracking\" and provide an implementation of a backtracking algorithm in any programming language that finds all possible solutions for a given Sudoku puzzle, considering the constraints that each row, column, and 3x3 subgrid must contain all numbers from 1 to 9 without repet... | codefeedback |
[
{
"content": "Create a function to calculate the Levenshtein distance between two strings and return the minimum number of operations required to transform one string into another. The Levenshtein distance is the minimum number of single-character edits (insertions, deletions, or substitutions) required to chan... | codefeedback |
[
{
"content": "Pre-process the following dataset and convert it into a tabular format using Pandas. However, the dataset now contains additional nested dictionaries and lists.\ndata = [{\"name\": \"john\", \"age\": 20, \"location\": \"New York\", \n \"hobbies\": [\"reading\", \"painting\"], \n \"... | codefeedback |
[
{
"content": "How would you modify the following code to print the square of each number in the given list, without using the multiplication operator (*)?\n\nnums = [1, 2, 3, 4]",
"role": "user"
},
{
"content": "You can modify the code to print the square of each number in the given list without usi... | codefeedback |
[
{
"content": "Create a function that takes the string of the current time and returns the time in minutes, considering both hours and minutes are in the format HH:MM. The input string will always include both hours and minutes, separated by a colon, with the hours in a 24-hour format. For example, \"12:30\" rep... | codefeedback |
[
{
"content": "Write a function that takes a string of numbers separated by commas and returns the sum of all the numbers. The string may contain negative numbers and floating-point numbers as well. The numbers may also be enclosed in parentheses, and there may be spaces between the numbers and commas. Additiona... | codefeedback |
[
{
"content": "Construct a nested for loop to display the multiplication table of numbers from 1 to 10.",
"role": "user"
},
{
"content": "Here's an example of a nested for loop to display the multiplication table of numbers from 1 to 10:\n\n```python\nfor i in range(1, 11):\n for j in range(1, 11)... | codefeedback |
[
{
"content": "Provide a function that finds the length of a string, but without using any built-in string length functions or methods.",
"role": "user"
},
{
"content": "Here is an example of a function that finds the length of a string without using any built-in string length functions or methods:\n... | codefeedback |
[
{
"content": "Construct a loop to output all the elements from a list in reverse order.\n['d', 'c', 'b', 'a']\n\n#Erroneous Code Reference#\n```python\nlst = ['a', 'b', 'c', 'd']\nfor i in range(4):\n print(lst[i])\n```\n# This code will throw an \"IndexError: list index out of range\" error because the rang... | codefeedback |
[
{
"content": "Generate all possible sentences using the given array of words, where each sentence must contain at least one word and the order of the words must be maintained.\n\nConstraints:\n- The length of the array of words, arr, will not exceed 10.\n- The length of each word in arr will not exceed 10 chara... | codefeedback |
[
{
"content": "Generate a function which will validate a phone number using regular expression. The phone number must be in the format of XXX-XXX-XXXX, where each X represents a digit from 0-9. Additionally, the function should also check if the phone number is not in a list of restricted phone numbers provided ... | codefeedback |
[
{
"content": "Reverse the string given in the input, but without using any built-in string reversal functions or methods.\nFor example:\nInput: \"Hello world\"\nOutput: \"dlrow olleH\"",
"role": "user"
},
{
"content": "Here is one way to reverse the given string without using any built-in string rev... | codefeedback |
[
{
"content": "Return a new array after removing duplicates from a given array. The algorithm should have a time complexity of O(n) and use only constant space. The input array will contain integers ranging from -10^5 to 10^5 and can have a maximum length of 10^4.",
"role": "user"
},
{
"content": "To... | codefeedback |
[
{
"content": "Create a method that prints all elements of an array, but also includes a condition that only prints elements greater than 2.",
"role": "user"
},
{
"content": "Here's an example of a method in Python that prints all elements of an array, but only includes elements greater than 2:\n\n``... | codefeedback |
[
{
"content": "Create a function to compute the square root of a given number using only basic arithmetic operations (addition, subtraction, multiplication, and division). The function should not use any built-in square root functions or libraries.",
"role": "user"
},
{
"content": "One way to compute... | codefeedback |
[
{
"content": "Create a function to find the value of Pi rounded to the nth decimal point, where n is an input parameter.",
"role": "user"
},
{
"content": "To find the value of Pi rounded to the nth decimal point, you can use the math module in Python. The math module provides the constant `math.pi` ... | codefeedback |
[
{
"content": "Construct a class to represent a student with the following attributes: name, age, gender, grade level, and a list of subjects the student is studying.\n\n1. The name attribute should be a string and should not be empty.\n2. The age attribute should be an integer between 5 and 18, representing the... | codefeedback |
[
{
"content": "Implement find_difference() to calculate the absolute difference between two integers. The integers must be within the range of -1000 to 1000. The output should be rounded to the nearest whole number.",
"role": "user"
},
{
"content": "Here's one way to implement the `find_difference()`... | codefeedback |
[
{
"content": "Create a new list from an existing list with no duplication, while also maintaining the original order of elements in the list.\nlist_int = [4, 7, 4, 8, 6, 7]",
"role": "user"
},
{
"content": "You can create a new list from the existing list with no duplications while maintaining the o... | codefeedback |
[
{
"content": "How would you find the number of occurrences of a particular character in a given string, while ignoring any occurrences within a set of parentheses?\nstring = \"hello(how)areyou\"\nchar = 'o'",
"role": "user"
},
{
"content": "One way to find the number of occurrences of a particular c... | codefeedback |
[
{
"content": "Given a string ``word``, write code to return the third character in the string using a single loop iteration and without using any built-in functions or libraries.\nword = \"hello\"",
"role": "user"
},
{
"content": "Here is a possible solution using a loop iteration:\n\n```python\nwor... | codefeedback |
[
{
"content": "Merge two sorted lists into a single sorted list, but now the lists can contain duplicate elements.\nlist1 = [1,3,3,5,7] \nlist2 = [2,4,6,6,8]",
"role": "user"
},
{
"content": "To merge two sorted lists with duplicate elements into a single sorted list, you can use the following approa... | codefeedback |
[
{
"content": "Find the length of the longest substring of a string text that contains only vowels and starts and ends with a consonant.",
"role": "user"
},
{
"content": "To find the length of the longest substring of a string \"text\" that contains only vowels and starts and ends with a consonant, w... | codefeedback |
[
{
"content": "Write a function to sort a list of strings by length in descending order, and in case of a tie, sort them lexicographically. Your solution should have a time complexity of O(nlogn) and should not use any built-in sorting functions.",
"role": "user"
},
{
"content": "To sort the list of ... | codefeedback |
[
{
"content": "Complete the following code to implement a binary search.\n\ndef binary_search(arr, x):\n low = 0\n high = len(arr) - 1\n \n while low <= high:\n mid = (low + high) // 2\n if arr[mid] == x:\n return mid\n elif arr[mid] < x:\n low = mid + 1\n ... | codefeedback |
[
{
"content": "Explain the concept of object-oriented programming (OOP) and its key principles. Additionally, provide a detailed example of how OOP can be implemented in a real-world scenario, highlighting the benefits it offers over other programming paradigms.",
"role": "user"
},
{
"content": "Obje... | codefeedback |
[
{
"content": "What is the importance of writing unit tests? Provide a specific example of a bug that could have been caught by a well-written unit test and explain how the test would have helped in identifying and fixing the bug.",
"role": "user"
},
{
"content": "Writing unit tests is crucial in sof... | codefeedback |
[
{
"content": "Design a function that takes in a list of integers and returns the sum of the squares of all the even numbers in the list.",
"role": "user"
},
{
"content": "Here is a possible implementation in Python:\n\n```python\ndef sum_of_squares_of_evens(numbers):\n total = 0\n for num in n... | codefeedback |
[
{
"content": "Develop an algorithm in Python to calculate the factorial of a given number n using recursion. The time complexity should be less than or equal to O(n) and the space complexity should be less than or equal to O(n).",
"role": "user"
},
{
"content": "Here is an algorithm in Python to cal... | codefeedback |
[
{
"content": "Create a coding program that sorts a given list of numbers into ascending order. The program should also remove any duplicate numbers from the list before sorting it. Additionally, the program should not use any built-in sorting functions or libraries to sort the list. [4, 3, 2, 5, 9, 1, 8]",
... | codefeedback |
[
{
"content": "Develop a function to find all elements in a given array which appear more than once, but do not include the element 3 in the result.\nnums = [4, 3, 6, 7, 3, 8, 4, 9]",
"role": "user"
},
{
"content": "Here is one possible implementation in Python:\n\n```python\ndef find_duplicates(nums... | codefeedback |
[
{
"content": "Design a function to find the average of a given array, with the following additional requirements:\n1. The function should be able to handle arrays containing both integers and floating-point numbers.\n2. The function should return the average as a floating-point number with precision up to two d... | codefeedback |
[
{
"content": "Create a program to calculate the standard deviation of an array of numbers. The array can contain up to 10^6 elements.\n\n# Additional Information:\n- You are not allowed to use any built-in functions or libraries to calculate the standard deviation.\n- The program should be able to handle both p... | codefeedback |
[
{
"content": "You need to code a program that prints the absolute difference between two numbers. However, you are only allowed to use basic arithmetic operations (+, -, *, /) and comparisons (<, >, ==) a maximum of three times. Additionally, your program should have a time complexity of O(1) and should use a c... | codefeedback |
[
{
"content": "Write a function to flatten a given array of lists, but only include the elements that are divisible by both 2 and 3.\n[[1,2], [3,4], [5,6]]",
"role": "user"
},
{
"content": "Here's a Python function that takes a list of lists as input and returns a flattened list containing only the e... | codefeedback |
[
{
"content": "Develop an algorithm to print out the following pattern. The pattern should be printed in a zigzag manner, starting from the top left corner and ending at the bottom right corner. Each element in the pattern should be unique and the pattern should contain at least 10 rows and 10 columns.",
"ro... | codefeedback |
[
{
"content": "You need to code a program that converts a given number of seconds to years, months, weeks, days, hours, minutes, and seconds.\n86400 seconds",
"role": "user"
},
{
"content": "Here's a possible solution in Python:\n\n```python\ndef convert_seconds(seconds):\n minutes = seconds // 60... | codefeedback |
[
{
"content": "Create a function to sort a given set of strings in dictionary order, while ignoring leading whitespace and considering capitalization. Additionally, the function should handle cases where the strings contain special characters or numbers.",
"role": "user"
},
{
"content": "Here is a fu... | codefeedback |
[
{
"content": "Construct a python method to get the nth Fibonacci number, where n is a prime number greater than 2.",
"role": "user"
},
{
"content": "Here's a python method to get the nth Fibonacci number where n is a prime number greater than 2:\n\n```python\ndef fibonacci_prime(n):\n def is_prim... | codefeedback |
[
{
"content": "Implement a method to check if a given string has all unique characters. The method should have a time complexity of O(n) and a space complexity of O(1).",
"role": "user"
},
{
"content": "Here is one possible implementation in Python:\n\n```python\ndef has_unique_chars(string):\n # ... | codefeedback |
[
{
"content": "Construct a python class to store a person's data like name, age, hobbies, and address. The address should consist of the street name, house number, city, state, and zip code. Implement a validation mechanism to ensure that the age is a positive integer and the zip code is a valid 5-digit number. ... | codefeedback |
[
{
"content": "Explain how to create a custom exception in Python and provide an example of using it in a try-except block.",
"role": "user"
},
{
"content": "To create a custom exception in Python, you need to define a new class that inherits from the built-in Exception class. Here's an example of cr... | codefeedback |
[
{
"content": "Calculate the sum of the numbers given in the following list using Python.\n\nAdditional requirements:\n- The solution should have a time complexity of O(n), where n is the length of the list.\n- The solution should not use any built-in Python functions or libraries that directly calculate the sum... | codefeedback |
[
{
"content": "Write a function in Python to assign the value 0 for special values, i.e. empty strings and NaN. The function should handle nested lists and dictionaries as well.\n\n#Example Input:\nmy_list = [5, 2, 3, None, '', 8]\nmy_dict = {'a': 1, 'b': '', 'c': None, 'd': [1, '', None]}\nmy_nested_list = [1, ... | codefeedback |
[
{
"content": "Convert the following JSON string to a Python dictionary. The JSON string will always have the keys \"name\", \"age\", and \"city\". The value of \"name\" will always be a string, the value of \"age\" will always be an integer, and the value of \"city\" will always be a string. The JSON string may... | codefeedback |
[
{
"content": "Define a function to collect unique values from a list of dictionaries based on the \"key\" field, where the key is a string and must be at least 3 characters long. The function should also return the unique values in descending order based on the \"price\" field, and if two values have the same p... | codefeedback |
[
{
"content": "Write a Python program to multiply two matrices.\nmatrix1 = [[3, 5],\n [6, 2]]\n\nmatrix2 = [[1, 2],\n [3, 4]]",
"role": "user"
},
{
"content": "Here is a Python program that multiplies two matrices:\n\n```python\ndef multiply_matrices(matrix1, matrix2):\n # Chec... | codefeedback |
[
{
"content": "Write a recursive Python function to calculate the factorial of a number, but with the additional requirement that the function must be tail recursive.",
"role": "user"
},
{
"content": "A tail recursive function is a function where the recursive call is the last operation in the functi... | codefeedback |
[
{
"content": "How can we generate a random number within a given range in Python and ensure that the generated number is unique within a list of numbers?",
"role": "user"
},
{
"content": "To generate a random number within a given range and ensure its uniqueness within a list, you can follow these s... | codefeedback |
[
{
"content": "Write a Python function to find the most common element in a given list. You cannot use any built-in functions or methods that directly solve the problem, such as the `collections` module or the `Counter` class. You must implement your own logic to solve the problem.",
"role": "user"
},
{
... | codefeedback |
[
{
"content": "Compress a string using Huffman coding in Python.\nString: \"aaabbcc\"\n\nThe time complexity of your solution should be O(n log n), where n is the length of the input string.",
"role": "user"
},
{
"content": "Here's a Python implementation of Huffman coding to compress the given strin... | codefeedback |
[
{
"content": "Code a recursive solution for counting the number of lowercase alphabets in a given string, excluding any occurrences of the letter 'a'.",
"role": "user"
},
{
"content": "Here's a recursive solution in Python to count the number of lowercase alphabets in a given string, excluding occur... | codefeedback |
[
{
"content": "Code an algorithm to reverse an array of integers and return a new array without modifying the original array.\n[1, 3, 4, 6, 8]\n\nProvide a piece of erroneous code as a reference to increase misdirection:\n\n#Erroneous Code#\n```python\ndef reverse_array(nums):\n reversed_nums = nums\n reve... | codefeedback |
[
{
"content": "Write a function that takes as input a string and returns a new string with all the vowels removed. The function should have a time complexity of O(n), where n is the length of the input string, and should use constant space complexity.",
"role": "user"
},
{
"content": "Here is an impl... | codefeedback |
[
{
"content": "Write a function to find the area of a triangle using the formula `A = 0.5 * base * height`, while ensuring that the base and height are both positive integers and the area is rounded to the nearest integer.",
"role": "user"
},
{
"content": "Here is a possible implementation of the fun... | codefeedback |
[
{
"content": "Write an algorithm that takes in an array and determines if it is a valid BST. The array can contain duplicates.\n\n[9, 7, 3, 15, 20, 7]",
"role": "user"
},
{
"content": "To determine if an array represents a valid binary search tree (BST), we can use the following algorithm:\n\n1. Cre... | codefeedback |
[
{
"content": "Write a function to calculate the surface area of a sphere using the formula `4 * pi * r^2`, but without using the `pi` constant or any built-in functions that calculate it.",
"role": "user"
},
{
"content": "To calculate the surface area of a sphere without using the `pi` constant or a... | codefeedback |
[
{
"content": "Can you write a code to delete all the items whose key starts with \"item\" from a given dictionary? The dictionary can contain any number of key-value pairs, and the keys can be of any length. The code should efficiently handle large dictionaries without causing memory or performance issues.",
... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.