instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Implement a function to perform arithmetic subtraction between two numbers, where one number is positive and the other is negative, using only bitwise operators. | codefeedback |
Access the third element from a list that contains 1 billion integers. | codefeedback |
Compare two values, A and B, to check if A is greater than B and if so, print "A is greater than B". Additionally, ensure that A and B are both prime numbers within the range of 1 to 1000. | codefeedback |
Given a table named "users" with the following columns: "id" (integer), "name" (string), "age" (integer), and "gender" (string). Write an SQL query to limit the output to the first 10 rows, considering only the rows with an even ID. Additionally, the rows should be ordered by age in descending order and then by name in... | codefeedback |
Generate a C++ function to print the Fibonacci series using recursion, memoization, and dynamic programming.
Requirements:
1. The function should take an integer n as input and print the Fibonacci series up to the nth term.
2. The function should use recursion, memoization, and dynamic programming to calculate the Fib... | codefeedback |
Implement a function that creates a dictionary from two lists which contain the keys and values, respectively. The function should handle cases where the keys list may contain duplicate values and the values list may contain different data types. Additionally, the function should ignore any keys that are empty strings ... | codefeedback |
Create a GraphQL query to get the list of products from a database, but the query should only return products that have a price higher than a given value and are in stock. Additionally, the query should also include a filter to only return products that have a specific color or belong to a certain category. | codefeedback |
In Java, how do you make a method that takes a number and displays its square root rounded to the nearest whole number, but only using bitwise operations and without using any built-in mathematical functions or libraries? | codefeedback |
Write a function in R to filter out the words containing more than 8 letters and do not use any loops or built-in R functions like `filter()`, `grep()`, or `sapply()`. | codefeedback |
Create a class "Person" in Kotlin with first name, last name, age, and nationality as its fields.
However, the age field should be private and can only be accessed through a getter method. Additionally, the class should have a companion object called "Utils" that contains a static method called "calculateAgeInMonths" ... | codefeedback |
Write a Python code that takes a given string and returns the string in reverse, but with all uppercase letters converted to lowercase and all lowercase letters converted to uppercase. Additionally, remove any punctuation marks or special characters from the string before performing the conversion.
Example:
Input: "He... | codefeedback |
Write a neural network in Keras that can distinguish between 10 different species of animals, using a dataset with 100,000 labeled images. | codefeedback |
Take the following code and convert it from a for loop to a While loop. Additionally, you must now only print the squares of the odd numbers in the list "nums". You are not allowed to use the modulus operator (%) to determine if a number is odd or even. Instead, you should use a bitwise operation. You should write a se... | codefeedback |
Write code in Swift to print the Fibonacci Sequence to the first 50 prime numbers. Additionally, implement a function to calculate the factorial of a given number and use it to find the factorial of the 25th Fibonacci number in the sequence. | codefeedback |
Implement a class to create an object with the given characteristics:
Characteristics: Name, Age, Gender, Nationality
Note: The Nationality attribute should be a required field and should only accept values from a predefined list of countries. The list of countries should be stored in a separate file and should be loa... | codefeedback |
Write a code that takes two lists and finds the longest common substring, considering only substrings of length greater than or equal to 4 characters. If there are multiple common substrings of the same length, return the one that appears first in the first list.
list1 = ['cat', 'car', 'camel']
list2 = ['carry', 'cap'... | codefeedback |
Write a while loop to print all prime numbers from 20 to 0, excluding numbers that are divisible by 2 and 3. | codefeedback |
Write a Python code that takes a string and replaces all the non-alphanumeric characters with a given character, but only if the character is not surrounded by alphanumeric characters. The code should handle strings of any length efficiently.
string = 'Hello, world!'
character = '#'
Example Input:
string = 'Hello, w... | codefeedback |
Sort the given list of words in descending order based on the length of each word. If two or more words have the same length, sort them in alphabetical order. Return the sorted list.
words = ['daisy', 'apple', 'cat', 'zebra', 'elephant', 'banana', 'grape', 'lion', 'tiger', 'penguin', 'crocodile', 'jaguar', 'wolf', 'os... | codefeedback |
Create a Kendo-UI application to display an interactive grid with the following options: sorting, pagination, search filter, and editable cells.
In addition to the above requirements, the application should allow the user to perform CRUD operations on the grid data. The user should be able to add new rows, edit existi... | codefeedback |
Given a list of strings, write a code snippet to format the output as follows:
- Each string in the list should be printed on a new line.
- Each line should start with a line number followed by a colon.
- The line numbers should be left-aligned and padded with zeros if necessary.
- The line numbers should start from 1 ... | codefeedback |
Write a code that takes a positive integer and prints it out in words. The program should handle numbers up to 999,999,999.
Example:
Input: 123,456,789
Output: "One Hundred Twenty Three Million Four Hundred Fifty Six Thousand Seven Hundred Eighty Nine"
To achieve this, you should implement the following steps:
1. Rea... | codefeedback |
What command(s) should be added to the function to make sure the input list is sorted in ascending order?
def remove_duplicates(list):
# TODO: add command(s)
new_list = []
for element in list:
if element not in new_list:
new_list.append(element)
# Increasing the difficulty by not us... | codefeedback |
Write a program to find the sum of all odd numbers between 1 and 100 using a for-loop. Additionally, the program should only consider prime numbers in the calculation of the sum. | codefeedback |
Given a list of integers, find the largest prime number in the list and delete all occurrences of it. Return the modified list.
Example:
Input: my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Output: [1, 4, 6, 8, 9]
Note:
- The largest prime number in the list is 7, so all occurrences of 7 should be deleted from the list.
- Th... | codefeedback |
You are passed an array, a value, and a maximum length. Write a Python program to insert the value in the array at the end if and only if the resulting array does not exceed the maximum length. If the array exceeds the maximum length, truncate the array by removing the first element before inserting the new value. Addi... | codefeedback |
Given two lists of integers, find all the common elements between them and return them in sorted order. The input lists can contain duplicate elements. The common elements should not include any duplicates.
Additional requirements:
- The solution should not use any built-in sorting functions or data structures.
- The ... | codefeedback |
Please generate a recursive function for the following task:
Given a list of integers, "find the maximum and minimum elements present in the list" using the following steps:
1. If the list is empty, return None.
2. If the list contains only one element, return that element as both the maximum and minimum.
3. Divide th... | codefeedback |
Create a function in Python that takes a string and prints the frequency table of all its alphanumeric characters, excluding any special characters or whitespaces. The output should be sorted in descending order of frequency. The function should also ignore the case of the characters. The input string can have a maximu... | codefeedback |
Write a MySQL query that retrieves all data from the table 'Sales' for the date range 01-04-2021 and 15-04-2021 using the date column, while excluding any sales made on Sundays. Additionally, group the results by the product category and calculate the total sales amount for each category. Finally, sort the results in d... | codefeedback |
In the given Java program, replace the line number 3 with a line that outputs the remainder of dividing a user-inputted integer by 3. The program should prompt the user to enter an integer and handle any non-integer input gracefully. Additionally, modify the program to also check if the user-inputted integer is negativ... | codefeedback |
Create a program in C++ to find the maximum and minimum elements in an array of fixed size. The program should have a time complexity of O(n) and should not use any built-in sorting functions or data structures.
Provide an additional constraint: The program should use only a constant amount of extra space, i.e., no ad... | codefeedback |
Convert a Python function to a JavaScript function that only accepts positive integers greater than 1000 as inputs and returns their sum. | codefeedback |
Given a list containing strings, write a Python program to filter out unique strings and return them in descending order based on their lengths. However, if a string starts with a vowel, it should not be included in the output. The output list should also be sorted alphabetically if multiple strings have the same lengt... | codefeedback |
Editor a Swift code to add an item into an array in constant time complexity, without using the built-in append() method or any other built-in array methods. | codefeedback |
Create a function that takes in a list of integers and returns a new list containing only the prime numbers in the original list. The function should also check and validate that the input list contains at least 5 integers and no more than 100 integers. Additionally, the function should raise an exception if any non-in... | codefeedback |
Write a PL/SQL query to display the sum of salaries of all the employees in a given department, but exclude any employees whose salary is above a certain threshold. Additionally, you are required to only consider employees who have been with the company for more than a specified number of years. | codefeedback |
Create a convolutional neural network to classify images of handwritten digits, but this time the images are rotated and skewed randomly. | codefeedback |
Connect to a MongoDB database hosted on a remote server with a specific IP address, select specific fields (excluding the commonly used ones such as '_id' and 'name') from the collection 'products', filter the results based on a specific condition, and display the results in a customized format. Additionally, implement... | codefeedback |
Write a Java program for sorting a given list of numbers in descending order without using any built-in sorting functions or libraries. You are only allowed to use the bubble sort algorithm. The time complexity of your algorithm should be O(n^2) and the space complexity should be O(1).
unsortedList = [7, 6, 5, 4, 3, 2,... | codefeedback |
Design a function to select the nth smallest element from an array. The function should handle arrays of any length and should return -1 if the given value of n is greater than the length of the array.
int[] arr = {11, -2, 4, 9, -5, 7}
Examples:
1. arr = {11, -2, 4, 9, -5, 7}, n = 3
Output: 4
2. arr = {11, -2, 4,... | codefeedback |
Construct a C# program for calculating the sum of the first 100 prime numbers and displaying the result on the console. The program should also prompt the user to enter their name and display a personalized greeting message that includes their name. Additionally, the program should implement error handling to ensure th... | codefeedback |
Write a Java function for reversing a given array of integers in place. The function should not use any additional data structures and should modify the original array.
However, you are not allowed to use a loop to swap the elements one by one.
arr = [1,2,3,4,5,6] | codefeedback |
Write a Python code snippet for a function to calculate the number of distinct words in a given string. Ignore any punctuation or special characters. The function should also return a list of the most frequently occurring words in the string, sorted in descending order of frequency. Additionally, the function should ex... | codefeedback |
Construct a PHP script to redirect a page to another page after 4 seconds, but only if the user is logged in, has the necessary permissions, and the user's account has been active for at least 30 days. Additionally, the redirect should only occur if the current page meets certain criteria based on user input, including... | codefeedback |
Implement a multi-threaded Java program that simulates a cryptocurrency transaction system. The program should support the following functionalities:
1. Create a cryptocurrency wallet with an initial balance and support for multiple cryptocurrencies.
2. Allow multiple threads to transfer funds between wallets simultane... | codefeedback |
Write a C++ program for sorting a given list of numbers using bubble sort algorithm.
unsortedList = [7, 6, 5, 4, 3, 2, 1]
Requirements:
1. The bubble sort algorithm should be implemented using recursion instead of iteration.
2. The program should have a time complexity of O(n^2), where n is the length of the list.
3.... | codefeedback |
Modify the following Java code to print the second smallest element in a given array. The array size should be at least 5 and cannot exceed 100. The array elements should be unique and within the range of -100 to 100. | codefeedback |
Create a JavaScript function to encode a given string with Base64 encoding. The encoding should be case-sensitive and should not use any built-in Base64 encoding libraries or functions. The output should be in a specific format: each character in the encoded string should be represented by its ASCII value in hexadecima... | codefeedback |
Write an SQL query to select the 'name', 'email', and 'phone_number' columns from a table named 'users' where the 'age' is between 25 and 40 (inclusive), the 'country' is not 'United States', and the 'phone_number' is a valid 10-digit number (including the area code). Sort the result in ascending order by the 'name' co... | codefeedback |
Write an SQL query to select the names, salaries, and ages of employees from a table named 'employees', in ascending order of the salaries. Additionally, only include employees who have a salary greater than the average salary of employees in the same department, and have been with the company for more than 2 years. | codefeedback |
Write a code snippet in JavaScript to get the date and time of the last day of any given month and year, while optimizing for both time and space complexity. | codefeedback |
Construct an XPath query to select all <h2> tags from a web page that have a class attribute starting with "title-" and containing the word "heading", and are nested within a <div> tag with an id attribute of "content". | codefeedback |
Create an array of size ten with the following conditions:
1. The first two slots should be filled with the value "even".
2. The next three slots should be filled with a randomly generated prime number.
3. The next two slots should be filled with the value "odd".
4. The next two slots should be filled with a randomly g... | codefeedback |
Write an SQL query to find the average salary for employees with the position of Manager at a company, while excluding any employees who have been with the company for less than 2 years. Additionally, include only those employees who have a performance rating of at least 4 out of 5. | codefeedback |
Describe how to access the fifth element in an associative array in PHP, but the array must contain at least 100 elements and the fifth element must have a key named "foo". Then modify its value to "Hello World". | codefeedback |
Write a bash script that installs a specific package (e.g., "nginx") in Ubuntu and other Linux-based systems, but only if the package version is greater than a specified version number. | codefeedback |
Create a Java method that takes a decimal number as an argument and returns its binary equivalent. The method should have a time complexity of O(log n), where n is the absolute value of the decimal number. Additionally, you should handle negative decimal numbers and throw a custom exception if the input is not a valid ... | codefeedback |
Write a Python function to check if a given number is a prime number or not. A prime number is an integer greater than 1 which is not divisible by any other numbers, except for 1 and itself. The function should also return the smallest prime number greater than the given number.
Additionally, the function should calcu... | codefeedback |
Write a C++ program to generate a Fibonacci sequence of length 20, where each number is the sum of the previous two numbers in the sequence. However, instead of starting with 0 and 1 as the first two numbers in the sequence, start with two arbitrary numbers that are provided by the user as input. | codefeedback |
Write a JavaScript code that implements a binary search algorithm.
arr = [1, 3, 5, 7, 9, 11]
target = 11
The code should be able to handle large arrays of up to 10^9 elements efficiently.
The code should also be able to handle duplicate elements in the array and find the first occurrence of the target value.
Additi... | codefeedback |
Create a function that multiplies each element of the input array by its index and returns the sum of the resulting array.
arr = [2, 3, 4] | codefeedback |
Implement a custom sorting algorithm in C that has a time complexity of O(n log n) and sorts elements in descending order. Additionally, the algorithm should handle duplicate elements in the input array and maintain their relative order in the sorted output.
For example, given the input array [3, 1, 4, 1, 5, 9, 2, 6, ... | codefeedback |
Using a specific programming language, create a web page that dynamically generates and displays a random quote each time the page is refreshed. The quote should be fetched from an external API and displayed in a visually appealing format. Additionally, implement a functionality that allows users to share the quote on ... | codefeedback |
Write a Java program to create a class for a circle, with parameters for the radius and center coordinates. The circle's radius should be greater than 0 and less than or equal to 100. The center coordinates should be integers between -100 and 100. The program should include methods for calculating the area and circumfe... | codefeedback |
Use LINQ syntax to create a query that returns all items from an array of strings, where the length of the string is a prime number, and the string contains at least one special character and one digit. | codefeedback |
Create an SQL query to select name, age, and city from a table called "users" for all users whose age is greater than 30 and city is either "New York" or "London". Additionally, sort the results in descending order of age and then ascending order of name. | codefeedback |
Write a PowerShell script that takes a user inputted date in the format "dd/mm/yyyy" and calculates the day of the week for that date, and then prints out the current date and the day of the week in the format "dd/mm/yyyy - Day of the Week". | codefeedback |
Generate a SQL query to select the average salary of all employees in the 'Marketing' department from a table named 'employee' where the department has at least 10 employees and the average salary is greater than $50,000. | codefeedback |
Build a function in JavaScript that takes two positive integers and returns the minimum value of the two. The function should handle cases where the integers are large (up to 10^9) efficiently. If the integers are negative or zero, the function should throw an error. Additionally, the function should only use a maximum... | codefeedback |
Write an SQL query to retrieve all the columns from a table named 'customers' where their address includes the string "Palm Street" and the customer's age is greater than 30, and the customer's last name starts with the letter 'S'. | codefeedback |
Design a Java method that takes an array of integers as an argument and prints the negative equivalent of each element in the array. The method should also throw a custom exception called "NegativeConversionException" if any of the elements in the array is not within the range of -100 to 100.
int[] array = {1, 2, 3, 1... | codefeedback |
## Problem Description ##
Write a Python program that finds the longest common subsequence of two strings, while considering case sensitivity and whitespace.
## Input ##
- Two strings `str1` and `str2` (1 <= len(str1), len(str2) <= 10^4)
## Output ##
- The longest common subsequence of `str1` and `str2`.
## Exa... | codefeedback |
Write a regular expression that captures all the words starting with a vowel and ending with a digit. | codefeedback |
You are tasked with creating a PHP script that opens a secure connection with a MySQL database using SSL encryption and sets the connection timeout to 5 seconds.
You should complete the following steps:
1. Import the necessary SSL certificates for establishing a secure connection with the MySQL server.
2. Create a ... | codefeedback |
Write a C++ code that implements the selection sort algorithm to sort an array of integers in descending order. The array must have at least 10 elements.
In addition to implementing the selection sort algorithm, you must also implement a function to generate a random array of integers. This function should take the si... | codefeedback |
Create a new data structure to store the following information and write an algorithm to access it. The data structure should support efficient insertion and deletion operations. Additionally, the algorithm should be able to handle duplicate keys and return all corresponding values when accessing a key. You are not all... | codefeedback |
Explain how to traverse a binary tree using breadth-first search (BFS) and provide the implementation in Python. Additionally, explain the time and space complexity of your implementation. Ensure that your solution does not use any built-in Python libraries or data structures for queue operations. | codefeedback |
Select all the records in the given table where the ID is a prime number greater than 10 and less than 1000. | codefeedback |
Create a function that takes in an array of positive integers and returns a new array containing the squared values of all odd elements of the given array. The squared values should be in ascending order. The input array must contain at least 10 elements. The squared values should be stored in a separate array. | codefeedback |
Create a function named `binary_search` that implements a binary search algorithm to find the index of a given goal value in a sorted list. The function should take in three parameters: `arr` (the sorted list), `goal` (the value to search for), and `compare_fn` (a function that compares two elements in the list). The f... | codefeedback |
Add an import statement to the code to import the regex module and use it to find all words in a given string that start with a vowel and end with a consonant, while ignoring words that contain any numbers or special characters. | codefeedback |
Create a for loop which will run from 1 to the given number. In each iteration, check if the current number is divisible by 3 and if it is, add the word "Fizz" to a list. If the current number is divisible by 5, add the word "Buzz" to the list. If the current number is divisible by both 3 and 5, add the word "FizzBuzz"... | codefeedback |
Write a function that takes a positive integer as an argument and prints its least significant digit. Additionally, the function should calculate and print the sum of the least significant digit and the second least significant digit. The function should also handle cases where the input is a negative integer, and in s... | codefeedback |
Create a function called `convert_csv_to_json` to convert the following csv to the corresponding JSON format. The csv contains information about cities and their geographical coordinates.
The csv file is structured as follows:
- The first line contains the headers: "city", "country", "latitude", and "longitude".
- The... | codefeedback |
Create a function that takes a list of strings as input and returns a dictionary where the keys are the input strings and the values are randomly generated numbers between 1 and 100. | codefeedback |
Rewrite the code for a binary search algorithm in a programming language of your choice, and analyze its time complexity in terms of Big O notation. Explain the concept of Big O notation and its significance in algorithm analysis. | codefeedback |
Rewrite the following code snippet so that it sorts the given list of integers in descending order instead of ascending order.
```
def sort_numbers(numbers):
for i in range(len(numbers)):
for j in range(i+1, len(numbers)):
if numbers[i] > numbers[j]:
numbers[i], numbers[j] = num... | codefeedback |
Convert the following snippet from ES6 to ES5, but also refactor it to use a closure for encapsulation. Additionally, introduce an error in the code to increase misdirection:
const multiply = (x, y) => { return x * y };
// Introduce an error in the code
console.log(multiply(2, 3)); // expected output: 6
In this task... | codefeedback |
Writing a regex pattern to match words starting with "Py" and ending with "thon" and containing at least one uppercase letter, with the additional requirement that the word must also contain at least one digit. | codefeedback |
Write a Python code to construct a dictionary from the given input.
key_arr = [100, 200, 300]
value_arr = ["apple", "banana", "mango"]
The keys in the key_arr are unique, but the values in the value_arr may not be unique. Your task is to construct a dictionary where the keys are the elements from the key_arr and the v... | codefeedback |
Generate a random string with the following conditions:
1. The string must start with a capital letter and end with a lowercase letter.
2. The string must contain at least one special character (!, @, #, $, %, ^, &, *) and at least one digit (0-9).
3. The string must have a length of at least 10 characters.
4. The stri... | codefeedback |
Increase the difficulty of the given programming test question by adding the following requirements:
1. The code should now print only the numbers from the range that are divisible by both 2 and 3.
2. The code should use list comprehension instead of a for loop to generate the fooBarArray.
3. The code should use a lam... | codefeedback |
Create a function called `replace_words` which replaces all the words specified in the given list of words with their corresponding synonyms. The function should handle multiple synonyms for each word. The input string may contain punctuation and uppercase letters. The function should preserve the original capitalizati... | codefeedback |
Replace all instances of a given character with another character, while also maintaining the original case sensitivity of the characters. The function should take in three parameters: the string (s), the character to be replaced (c), and the replacement character (r). Additionally, the function should only replace the... | codefeedback |
Find the area of a triangle using the Heron's formula, but the lengths of the sides must be inputted by the user. The program should prompt the user to enter the lengths of the sides of the triangle and then calculate the area using the Heron's formula. | codefeedback |
Develop an algorithm to concatenate two strings, ensuring that the resulting string is in all uppercase characters and contains only alphabetical characters. String 1 should have a maximum length of 10 characters, while string 2 should have a minimum length of 5 characters. | codefeedback |
Write a function to remove all occurrences of a specified element from a given list and return the modified list. The function should handle the following scenarios:
1. Empty List: If the input list is empty, return an empty list.
Example:
Input: [], element = 4
Output: []
2. No Occurrences: If the input list does no... | codefeedback |
Develop an algorithm to modify a given string by changing the case of each character, but only for the letters 'o' and 'l'. The rest of the characters should remain unchanged. The algorithm should have a time complexity of O(n), where n is the length of the string. Additionally, the algorithm should use constant space ... | codefeedback |
Write a function to find all elements that appear more than once in a given array. The function should return the elements in ascending order and should also remove any duplicate elements from the result. Additionally, you should not use any built-in functions or libraries to solve this problem. The input array will ha... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.