instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a function to print the maximum and minimum number in a given list, without using the built-in functions max() and min(). The function should also handle the case where the list contains duplicate numbers. The time complexity of the solution should be O(n), where n is the length of the list.
my_list = [5, 4, 7, ... | codefeedback |
Convert the following csv data into a JSON object. The program should validate that the "age" column contains only integer values and that the "id" column contains unique values. Additionally, the program should sort the JSON object based on the "age" column in ascending order. If any of the data in the "age" column is... | codefeedback |
Create a list comprehension to generate the first 1000 Fibonacci numbers. | codefeedback |
Create a function to calculate the sum of the Triangle Series up to the given number n, but the function should also return the number of terms in the series. Additionally, the function should only use a loop structure to calculate the sum, and not use any built-in mathematical functions or libraries.
Furthermore, the... | codefeedback |
Create a program to create a dictionary with words and their frequencies from a given sentence. The program should also remove any punctuation marks and convert all words to lowercase before counting their frequencies. Additionally, the program should exclude common English words such as "the", "is", and "and" from the... | codefeedback |
Implement a function to replace every occurrence of an old string in a given string with a new string, while preserving the original case of the letters. The function should also handle multiple occurrences of the old string in the given string. The old string can be of any length and may contain special characters. Th... | codefeedback |
Write a SQL query to get the titles, release dates, and genres of all the movies from the Movies table released in the year 2019, where the movies must have a rating higher than 7.5, have at least 1000 user votes, and belong to the "action" genre. Additionally, the query should only include movies that have a runtime o... | codefeedback |
Write a JavaScript program to calculate the sum of the first 10,000 prime numbers that are also palindrome numbers. A palindrome number is a number that remains the same when its digits are reversed. | codefeedback |
Create a function to print all permutations of a string without duplicates. The string may contain duplicate characters. The function should have a time complexity of O(n!) and a space complexity of O(n!). | codefeedback |
Create an SQL query that lists the employee names with their corresponding department and salary, and also includes the total number of employees in each department. Additionally, the query should only include departments that have at least 3 employees and employee names should be sorted in descending order based on th... | codefeedback |
Create a class in C++ to compare two dates and determine the number of days between them, considering time zones.
The dates are provided as input in the format "MM/DD/YYYY". The class should have the following functionalities:
1. A constructor that takes in two date strings and the time zones of each date and initial... | codefeedback |
Create a NumPy array with all the elements set to 0, but the array size should be a multiple of 5 and the array must be reshaped into a 2D array with 5 columns. The reshaped array must have the sum of each row equal to a prime number and the product of each column equal to a perfect square. | codefeedback |
Create an SQL query to select the names and ages of employees who have been with the company for more than 5 years and have a salary greater than $50,000. Additionally, display the average salary of all employees in the result set. | codefeedback |
Create a function that takes two positive integers, n and m (where m > n), and returns an array that contains the squares of the numbers from n to m (inclusive). The function should also ensure that n and m are within the range of 1 to 10^9 (inclusive). Additionally, the function should return the result in descending ... | codefeedback |
Create a function that finds the longest common prefix of two strings. The strings should have a length of at least 3 characters. The function should also handle cases where the strings contain special characters and ignore them when finding the common prefix. Additionally, the function should be case-insensitive, mean... | codefeedback |
Edit the following code to print out the nth Fibonacci number, but with the constraint that the code must use a recursive algorithm without using any additional variables or data structures, and the code must have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Create a for loop that prints the numbers 0 to 100 and prints if the number is a prime number or not. Additionally, the program should also calculate and display the sum of all prime numbers encountered during the loop. | codefeedback |
Create a function in Python called "cube_divisible_by_3" that takes in a range of positive integers as input and returns an array containing the cube of all the numbers in the range that are divisible by 3, excluding the number 5. The function should handle error cases where the input is not a range of positive integer... | codefeedback |
Write a function to group a list of strings based on the first two characters of each string. The function should return a dictionary where the keys are the first two characters and the values are lists of strings that start with those characters.
You are not allowed to use any built-in functions or libraries that dir... | codefeedback |
Write a function that sums the elements of an array, but exclude any negative numbers from the summation. If the array contains any duplicates, count them only once in the summation. | codefeedback |
Create a function that reverses the elements of a given array without using any built-in array reverse function or using any additional array or data structure. Additionally, the function should handle arrays that contain both integers and strings. | codefeedback |
Create an SQL query that selects the names, addresses, and phone numbers of all employees who have been with the company for at least 5 years, have a salary greater than $50,000, and have a job title of "Senior Accountant" or "Finance Manager". Additionally, the query should display the total number of employees from e... | codefeedback |
Find the two smallest prime numbers in an array such that their sum is equal to a given value and their product is also a prime number. The array will only contain positive integers.
array = [7, 2, 9, 3, 5, 11]
value = 10 | codefeedback |
Create a function in C++ that capitalizes the first letter of every word in a given string. The function should also handle cases where the given string contains punctuation marks, numbers, and special characters, and multiple spaces between words. Additionally, the function should ignore capitalization if the first le... | codefeedback |
Determine whether the given string is a valid IPv4 address, taking into account that each octet should be between 0 and 255, leading zeros are not allowed, and there should be exactly 4 octets separated by periods. The octets cannot be all zeros or all 255. | codefeedback |
Implement a class that stores values of all data types, including complex numbers and user-defined data types. The class should also support serialization and deserialization of its objects to and from a file. | codefeedback |
Correct the syntax errors in the following JavaScript snippet and refactor the code to use a switch statement instead of an if-else statement. Additionally, ensure that the variable "outpt" is declared as a constant and initialize it to 0 before the conditionals. The code should also be optimized to use a single return... | codefeedback |
Write a Python code to open a web page, print its content, count the number of words in the content, and determine the frequency of each word.
url = "www.wikipedia.org" | codefeedback |
Calculate the total number of possible binary trees with n nodes, where each left subtree has a prime number of nodes and each right subtree has a Fibonacci number of nodes. | codefeedback |
Write a SQL query to select the elements from the table whose ID is not present in the given python list, and whose price is greater than 100. Additionally, the query should only return rows where the element's name starts with a vowel and ends with a consonant. | codefeedback |
Write a code snippet for sorting an array of integers in descending order using the bubble sort algorithm.
arr = [12,9,7,8,6]
Additional requirements:
- The time complexity of your solution should be O(n^2) in the worst case.
- The space complexity of your solution should be O(1).
- You are not allowed to use any buil... | codefeedback |
Write a SQL query to find out the total number of books purchased by each customer in a book store, excluding any books with a price higher than $50. Additionally, display the average price of the books purchased by each customer, but only for customers who have made at least 5 purchases. | codefeedback |
Write a code to detect the data type of a given variable and return "integer" if it is an integer, "float" if it is a float, "string" if it is a string, "list" if it is a list, "dictionary" if it is a dictionary, and "unknown" if it is any other data type. The code should handle nested lists and dictionaries as well. T... | codefeedback |
Construct a C program to print all lexicographically sorted permutations of a given string. The program should also count and print the total number of permutations generated. The input string will have a maximum length of 12 characters and will consist only of lowercase letters. | codefeedback |
Compute the maximum sum of elements of a given subarray of length k in an array of integers, but you cannot use any built-in functions or methods for calculating the sum of the subarray. Additionally, you cannot use any variables to store intermediate sums or the final maximum sum. You are only allowed to use a single ... | codefeedback |
Design an algorithm to sort an array using Quick Sort.
Array: [5, 3, 6, 2, 1, 4]
You are not allowed to use any built-in sorting functions or methods.
Erroneous Code:
```
def quick_sort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
right = ... | codefeedback |
Translate this code snippet into a pseudocode. Additionally, modify the code to print the sum of all odd numbers within the given range of 3 to 10. | codefeedback |
Design a program to find the longest palindrome inside a given string that contains only lowercase alphabets and numbers. The palindrome should have the following properties:
- It should be a perfect square.
- The sum of its digits should be a prime number.
- The sum of the squares of its digits should be a perfect cub... | codefeedback |
Write a function in Python to convert a given decimal number into its binary form, without using the built-in `bin()` function. The function should have a time complexity of O(log n) and a space complexity of O(log n), where n is the given decimal number. Additionally, the function should handle negative decimal number... | codefeedback |
Write a SQL statement to find employees whose salary is greater than a given threshold, but also include employees whose salary is within 10% of the threshold. The salary threshold is set at $60,000.
Additionally, you need to consider the following conditions:
1. Only include employees whose employment status is curre... | codefeedback |
Increase the difficulty of the given programming test question:
Implement a method to find the shortest path between two points in a two-dimensional array using Dijkstra's algorithm. The two-dimensional array will contain non-negative integers. You need to handle cases where there are no valid paths between the start ... | codefeedback |
Add functionality to a given Python class to retrieve a book's ISBN by its title. Additionally, implement a method to retrieve the book title by its ISBN. The class should also include a method to add a new book to the library by providing its title and ISBN.
To increase the difficulty of this question, you can consid... | codefeedback |
Construct an algorithm to search for the Given Normalised Word in a Normalised Trie, ensuring that the word contains only lowercase letters. The Normalised Trie should be implemented using a recursive data structure. Additionally, the algorithm should return the number of occurrences of the Given Normalised Word in the... | codefeedback |
Write a code to convert a string to a float in Python without using any built-in conversion functions or libraries. The input string may contain leading or trailing white spaces, a sign (+/-), and a decimal point. However, it will always be a valid floating-point number representation.
Example:
Input: " +12.345 "
... | codefeedback |
Implement a function in Python that takes an array of positive integers and returns the index of the first occurrence of the maximum element. Additionally, handle the case when the input array is empty and raise a custom exception called "EmptyArrayError". The function should also check if the input array contains any ... | codefeedback |
Create a query to find all users younger than 19 years old and whose account is active in a database table called "users". Sort the results in descending order of their age. | codefeedback |
Create a Java program to convert a 2D array of positive integers into a single positive integer. The 2D array represents a matrix, where each element in the array represents a digit. The resulting integer should be obtained by reading the digits row by row, from left to right. The input array is guaranteed to have at l... | codefeedback |
Please write a Python function that finds the number of unique words in a given sentence, while ignoring any punctuation marks or special characters. The function should return the count of unique words.
sentence = "This is a test sentence! Can you handle punctuation marks?"
#Expected Output: 8 | codefeedback |
Write a code to count the repeated words in a given sentence, excluding any words that contain the letter 'e'. Additionally, exclude any words that are plural nouns.
"For example, consider the sentence: 'The cats are sleeping. The cat is awake.' In this sentence, the word 'cats' should be excluded from the count as it... | codefeedback |
Compare two nested JSON objects in Python. The JSON objects may contain multiple nested levels with different data types and the comparison should consider all the nested levels and data types. Additionally, you should also implement a function to handle circular references within the JSON objects, where a nested objec... | codefeedback |
Find the maximum value from a nested Python dictionary, where the nested dictionary can have any number of levels and each level can have any number of keys and values. The values can be either integers or lists of integers.
sample_dict = {'a': {'x': [10, 20], 'y': [30, 40]}, 'b': {'x': [50, 60], 'y': [70, 80]}, 'c': ... | codefeedback |
Write a function to measure the similarity between two strings. The similarity score should be a value between 0 and 1, where 1 indicates that the strings are identical and 0 indicates no similarity. The function should take into account both the character similarity and the order of the characters in the strings.
Add... | codefeedback |
Output the 100 most populous cities along with their respective countries, populations, and land areas. Additionally, display the percentage of the country's population that resides in each city. | codefeedback |
Edit the code to check whether the given number is a triangle number. A triangle number is a number that can be represented as the sum of consecutive positive integers starting from 1. The function should return True if the number is a triangle number and False otherwise. The input number will be an integer greater tha... | codefeedback |
Generate a function to implement the following purpose in Java:
Find the square root of a given number using only bitwise operators and without using any built-in mathematical functions or libraries.
To increase the difficulty, please implement the square root algorithm using the following steps:
1. Implement a binary... | codefeedback |
Create a function to extract the top 10 keywords from a given text.
Additional Instructions:
1. The function should ignore common words such as "is", "that", "am", and "to".
2. The function should count the frequency of each keyword in the text.
3. The function should return the top 10 keywords based on their frequenc... | codefeedback |
## Problem Description ##
You are given two strings, `string1` and `string2`. Write a function `find_differences` that takes in these two strings as input and returns a list of tuples. Each tuple should contain the index and the characters where the strings differ. The function should consider differences in letter cas... | codefeedback |
Create a convolutional neural network using TensorFlow for image classification with the following requirements:
1. Use a dataset with at least 50,000 images for training and 10,000 images for testing.
2. Implement a data augmentation technique, such as random rotation or horizontal flipping, to increase the size of t... | codefeedback |
Find the most frequent character in an inputted string, considering both uppercase and lowercase characters. The input string will have a maximum length of 1,000,000 characters. The time complexity of your solution should be O(n), where n is the length of the input string. | codefeedback |
Given a string, find the word with the longest length. The word must contain at least two vowels and two consonants, with the vowels appearing before the consonants. The input string will not exceed 1000 characters. | codefeedback |
Create a function that takes in a list of strings and an integer n, and returns a new list of only the strings that contain both uppercase and lowercase letters, and have a length greater than or equal to n. | codefeedback |
Generate code to generate a random number between 100 and 500, divisible by 7. | codefeedback |
Create a web application that allows users to manage a database of employees with the following requirements:
1. The application should have a login system with authentication and authorization for different user roles (e.g., admin, manager, employee).
2. The admin role should be able to add, edit, and delete employee... | codefeedback |
Write a function that takes in a positive integer as input and returns the sum of the cubes of each digit in the number. | codefeedback |
Write an SQL query to find the total number of books in the library that were published in the last 5 years, have a rating of at least 4.0, and have been borrowed at least 10 times. | codefeedback |
Generate a code that concatenates a reversed copy of a given string to itself, but only include the alphabetic characters in the reversed copy. Ignore any non-alphabetic characters. Additionally, ensure that the reversed copy is case-insensitive, meaning that uppercase and lowercase alphabetic characters should be trea... | codefeedback |
Create an algorithm that finds the maximum element of an array. The array can contain both positive and negative integers. However, you are not allowed to use any comparison operators (such as > or <) in your algorithm. | codefeedback |
Implement a binary search algorithm in Python that also accounts for duplicates in the list. | codefeedback |
Use the given function to convert an integer to a string, ensuring that the resulting string contains only numeric characters and has a length of exactly 8 digits. Additionally, implement a validation check to ensure that the integer provided is not negative. | codefeedback |
Write code for sorting an array in-place using the Bubble Sort algorithm. The array should be sorted in descending order. The time complexity of the algorithm should be O(n^2), and the space complexity should be O(1).
Provide a piece of erroneous code as a reference to increase misdirection:
```python
def bubble_sort(... | codefeedback |
Use the given function to generate a random password of the specified length. Additionally, make sure that the password contains at least one uppercase letter, one lowercase letter, one digit, and one special character. To further increase the difficulty, ensure that the password is not vulnerable to common password cr... | codefeedback |
Write a python program to determine whether a given number is a perfect square or not. Additionally, calculate the square root of the number without using any built-in functions or libraries. The time complexity of the solution should be O(log n), where n is the given number. | codefeedback |
Write a function that takes a string as input and returns true if the string is a palindrome, false otherwise. A palindrome is defined as a word, phrase, number, or other sequence of characters that reads the same forward and backward, disregarding spaces, punctuation, and capitalization. The function should ignore any... | codefeedback |
Create a program that prints out an Egyptian multiplication table up to a given number N. The program should validate the input to ensure that N is a positive integer greater than or equal to 1 and less than or equal to 100. Additionally, implement error handling to handle any potential input errors from the user, such... | codefeedback |
Create a Python class called "Person" with name and age as attributes. The name attribute should only accept strings with a length between 2 and 20 characters, inclusive. The age attribute should only accept integers between 0 and 120, inclusive. Additionally, the class should have a method called "calculate_age_in_day... | codefeedback |
Can you implement the bubble sort algorithm in a programming language of your choice? Additionally, please explain the time complexity of the algorithm and any possible optimizations that can be made to improve its performance. | codefeedback |
Create a function to generate a list of all prime numbers in a given range. The function should have a time complexity of O(n√m), where n is the length of the range and m is the maximum value in the range. Additionally, the function should use a space complexity of O(n), where n is the length of the range.
To make the... | codefeedback |
Create a React component to accept a list of items and render them in a table. The component should also include a search functionality that allows users to filter the items based on a specific criterion. Additionally, the component should implement pagination, displaying a limited number of items per page and allowing... | codefeedback |
Create a function that takes in a list of integers and returns the largest element. If there are multiple occurrences of the largest element, return the index of the first occurrence. If the list is empty, return -1.
For example, given the input [3, 9, 6, 2, 5], the function should return 9.
Write the function with t... | codefeedback |
Edit the given string by replacing all spaces with an underscore and removing all punctuation marks. Additionally, the string should be converted to uppercase. | codefeedback |
Create a function to merge two dictionaries in Python. The merged dictionary should not only combine the key-value pairs from both dictionaries, but also perform the following operations:
1. For keys that are present in both dictionaries, concatenate the values together into a single string. For example, if the first ... | codefeedback |
Create a MySQL statement to find the row with the lowest value in a column "Price" for products that have not been discontinued and are in stock, while also considering the following conditions:
1. The query should not use any subqueries.
2. The query should only make use of basic SQL functions and operators (e.g., MIN... | codefeedback |
Explain the differences between a class and an object, and describe their respective advantages and disadvantages in object-oriented programming. In addition, design a program that demonstrates the concept of inheritance, where a derived class inherits properties and methods from a base class, and provide an example of... | codefeedback |
Write a Bash script that checks if a given directory exists, and if it does, recursively count the total number of files with a ".txt" extension in the directory and all its subdirectories. | codefeedback |
Given a Python dictionary with integer keys and string values, write a function to convert the dictionary into a list of tuples. The function should also sort the tuples in ascending order based on the length of the string values in the dictionary. If two values have the same length, the tuples should be sorted in desc... | codefeedback |
Generate a program to convert a date in the format 'dd/mm/yyyy' to a date in the format 'yyyy/mm/dd' while taking into account leap years. The program should include robust error handling for invalid dates and should also handle dates before the year 1900.
To solve this problem, you can follow these steps:
1. Prompt t... | codefeedback |
Write an R program to find the factorial of a number using a recursive function. | codefeedback |
Write a Node.js script that takes an array of numbers [1,3,7] and multiplies each number by 2. However, you are not allowed to use any built-in array methods such as map(), forEach(), or reduce(). Additionally, the script should only use a single loop to iterate through the array and should not use any additional varia... | codefeedback |
Write a SQL query to list the names, addresses, phone numbers, and email addresses of all customers in the 'customer' table who have made at least one purchase from the 'orders' table. Additionally, include the total number of orders made by each customer and the average order amount for each customer. | codefeedback |
Generate a JavaScript program to check if a number is within a given range, but the lower bound and upper bound values can be dynamic and can only be prime numbers. | codefeedback |
Write a Java program to find the 10 numbers closest to the given number from a given array of numbers. The program should take the input number and the array as input from the user.
Additionally, the program should:
1. Handle cases where there are fewer than 10 numbers in the array. In such cases, the program should o... | codefeedback |
Write a code snippet using Python to print the following sentence "Programming is fun!" while ensuring that each word is printed on a separate line, all letters are in uppercase, and no built-in string manipulation functions (such as upper() or split()) are used. | codefeedback |
Use jQuery to toggle a div with the class 'hide' only if it is not currently animated and has a data attribute 'toggleable' set to true. Additionally, check if the div has a sibling element with a class of 'visible', and if it does, fade out the sibling element before toggling the div with the class 'hide'. | codefeedback |
Determine the sum of the squares of all even numbers in a given array. The array contains positive integers only, and it has a length of at most 100. The sum should be computed using a recursive function that takes the array as an input. Additionally, the function should return the number of even numbers in the array a... | codefeedback |
Explain the purpose of an immutable object in Python and provide an example to demonstrate its use in a real-world scenario. Additionally, implement a custom immutable class in Python that overrides the equality operator and supports deep copying. | codefeedback |
Convert a LinkedList of Person objects to an array of objects while ensuring that the array is sorted in ascending order based on the age attribute of the Person objects. Additionally, handle the scenario when there are duplicate age values in the LinkedList and ensure that the resulting array has distinct Person objec... | codefeedback |
Write a Java program to read an array of strings and sort them lexicographically (alphabetically) in descending order. The program should ignore case sensitivity when sorting.
String[] arr = {"apple", "cat", "Hello", "Hello", "Cat"};
#Expected Output#
Sorted array in descending order: hello, cat, cat, apple, apple | codefeedback |
Create a SQL query to find all users from the user table whose age is greater than 30, whose first name starts with the letter 'J', and whose last name ends with the letter 'S'. | codefeedback |
Write a Java program to find the common elements between two arrays, but instead of using the built-in array functions, you should implement your own logic to find the common elements. Additionally, optimize your solution to have a time complexity of O(n log n), where n is the size of the larger array. | codefeedback |
Write a Python function that takes in three side lengths as input and calculates the area, perimeter, and determines whether the triangle is right-angled or not.
Requirements:
- The function should have a time complexity of O(1) and a space complexity of O(1).
- The function should return the area, perimeter, and a bo... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.