instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Create a Swift playground page that takes two strings as an input. The first string should contain only lowercase alphabets and be at most 10 characters long, and the second string should contain only uppercase alphabets and be at most 15 characters long. The program should then convert the lowercase alphabets in the f... | codefeedback |
Create a MySQL query to calculate the average length of time spent by customers on your website, excluding any sessions that lasted less than 10 seconds. Additionally, exclude any sessions where the customer accessed more than 5 pages during their visit. | codefeedback |
Create a Racket function that takes two strings as an input and returns the number of distinct characters that appear in both strings, without using any built-in string or list manipulation functions.
String1 = "hello world"
String2 = "world hello"
You need to implement your own logic to check for the presence of eac... | codefeedback |
## Given Test ##
Write a PHP script to encode a string using base64.
String for encoding: abcdefg
Additional requirements:
1. The script should be able to handle strings of any length.
2. The script should use a custom implementation of the base64 encoding algorithm, rather than relying on built-in PHP functions.
3. T... | codefeedback |
Create an ID with a structure of JSON and explain the components of the JSON structure. Additionally, implement a function that can validate whether the JSON structure is valid or not.
Additional requirements:
1. The JSON structure must contain at least 5 different types of data, including string, number, boolean, arr... | codefeedback |
Implement a function that calculates the product of two integers, each having at most 100 digits. The function should have a time complexity of O(n), where n is the number of digits in the larger integer. Additionally, the function should not use any built-in multiplication or division operators. | codefeedback |
Write a PHP script to print the current date and time in the following format: '27th of April, 2020 at 5:30 AM'. Additionally, you should also display the number of seconds elapsed since the Unix epoch (January 1, 1970 00:00:00 UTC) and the number of days remaining in the current year.
To solve this problem, you can f... | codefeedback |
Write a C# code to check whether a given number is a prime number. The number can be of type int or long.
Additional requirements:
1. The code should be able to handle large numbers efficiently, i.e., it should work for numbers up to 10^18.
2. The code should be optimized to minimize the number of iterations required ... | codefeedback |
Write a code which generates the Fibonacci sequence, but each number in the sequence must be a prime number and contain at least four digits. | codefeedback |
Explain in detail how a hash table works, including its internal implementation and collision resolution strategies. Additionally, discuss the advantages and disadvantages of using a hash table as compared to other data structures.
Provide a step-by-step algorithm to insert and retrieve elements in a hash table. | codefeedback |
Create a program to calculate the area and the perimeter of a parallelogram.
The program should prompt the user to enter the length of the base and the length of one of the sides of the parallelogram.
The program should then calculate and display the area and perimeter of the parallelogram using the following formulas... | codefeedback |
Write a Ruby program to create a class called "Person" with variables such as name, age, gender, height, and weight. The program should also include methods for calculating the person's BMI (Body Mass Index) based on their height and weight. Additionally, the program should have a method to determine if the person is c... | codefeedback |
Construct a Javascript program to return the second largest prime number in an array. | codefeedback |
Create a function to determine whether one string is a substring of another. However, you are not allowed to use built-in string search methods such as `str.find()` or `str.index()`. Instead, you need to implement your own algorithm to find the substring.
The function should take two string parameters: `string_1` and ... | codefeedback |
Output the contents of the array ["Hello", "World", "AI", "Machine Learning"] using a for loop, but the output should be in reverse order. Additionally, only print the elements that have an odd number of characters in them. | codefeedback |
You need to edit the wrong sentence appropriately by using regular expressions to match and correct all instances of the word "likes" in the sentence. Additionally, you must ensure that the corrected sentence maintains proper grammar and punctuation throughout. | codefeedback |
Please create a function that calculates the average of a list of numbers, but with the following additional requirements:
1. The function should use the Observer design pattern to notify an observer object whenever a new number is added to the list.
2. The observer object should keep track of the maximum and minimum n... | codefeedback |
Rearrange the elements of the array [3, 1, 2, 5, 4] in ascending order using the bubble sort algorithm. The bubble sort algorithm works by repeatedly swapping adjacent elements if they are in the wrong order. Implement the bubble sort algorithm to solve this problem. Additionally, you must ensure that the algorithm has... | codefeedback |
Create a Python program to merge two lists by alternating elements, but the merged list should not contain any duplicates. Additionally, the program should sort the merged list in ascending order.
list1 = [2, 3, 5, 7, 9];
list2 = [4, 7, 10, 11];
Provide a piece of erroneous code as a reference to increase misdirect... | codefeedback |
Sort an array of characters in alphabetic order. The array must be sorted in ascending order and should also ignore case sensitivity. Additionally, the sorted array should have all the vowels (a, e, i, o, u) placed before the consonants. Finally, the sorting algorithm used should have a time complexity of O(n log n).
... | codefeedback |
Rewrite the following code using a lambda expression instead. The lambda expression must also use a conditional statement to check if the input is a positive number before squaring it.
def square(x):
if x > 0:
return x * x
else:
return "Invalid input"
# Solution using a lambda expression
squar... | codefeedback |
Compile a C program to display the prime numbers from 1 to 100, but only print the prime numbers that are palindromic, have a digit sum greater than 10, and are divisible by a prime number less than 10. | codefeedback |
Create a highly scalable and secure RESTful API that efficiently queries a database and returns results in a specific format. The API should have the following functionalities:
1. Create a new entry in the database:
- Endpoint: POST /data
- Input: JSON object containing the data to be stored
- Output: JSON ob... | codefeedback |
Display the sum of three random numbers from 1 to 6, excluding the number 3. Each number should only be used once. Additionally, the sum should be a prime number. | codefeedback |
Write a Java program to find the element that appears maximum number of times in an array. If multiple elements have the same maximum frequency, return the one with the highest value. The time complexity of the solution should be O(nlogn), where n is the size of the array.
int [] arr1 = {2, 8, 7, 2, 8, 2, 6, 7, 8, 7} | codefeedback |
Design a function in JavaScript to filter out the values of an array that are divisible by both 2 and 3, and are greater than the median value of the array.
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
In this case, you need to calculate the median value of the array and then filter out the values that are divisible by both 2 and ... | codefeedback |
Create a HTML page containing a form with five input boxes and implement the following additional functionalities:
1. Add validation to each input box to ensure that the user enters a minimum of 8 characters in each box.
2. Implement a "Submit" button that is disabled until all five input boxes have valid values and a... | codefeedback |
Construct a for-loop to print all prime numbers from 1 to n, separated by a space, with n being a positive integer greater than or equal to 10. | codefeedback |
Code a function to solve the Tower of Hanoi puzzle iteratively using stacks.
Additional Instructions:
- Implement the function iteratively, without using recursion.
- Use stacks to keep track of the movement of the disks.
- The function should take three parameters: the number of disks, the source stack, and the targe... | codefeedback |
Write a Python program to remove duplicate characters from the given string while preserving the original order of characters. The program should have a time complexity of O(n) and a space complexity of O(n), where n is the length of the string.
String: Hello world
#Additional Reasoning Steps#
1. Create an empty set ... | codefeedback |
Implement a sorting algorithm to sort the given array in ascending order.
#Additional Information#
The sorting algorithm should be efficient and have a time complexity of O(n log n).
#Example Input#
[4, 3, 8, 6, 7, 9, 2, 1]
#Example Output#
[1, 2, 3, 4, 6, 7, 8, 9]
#Incorrect Code for Reference#
```
def bubble_sort... | codefeedback |
Print a binary tree level by level, starting from the root level. Additionally, for each level, print the sum of the values of the nodes in that level. Ensure that the implementation is done using a depth-first search approach. | codefeedback |
Write a function to give the intersection of two unsorted linked lists. However, you are not allowed to use any extra space, the time complexity of your solution should be O(n+m), where n and m are the lengths of the two linked lists, and you are not allowed to modify the input linked lists in any way. | codefeedback |
Write a JavaScript program to validate the given input against a set of rules.
Rules:
1. Length should be equal to 10.
2. The input should contain at least one uppercase letter, one lowercase letter, and one special character.
3. The special character should be one of the following: ! @ # $ % ^ & * ( ) _ + - = { } [ ] ... | codefeedback |
Write a SQL command to join the 'customers', 'orders', and 'order_items' tables on the respective columns, but only include customers who have placed at least 5 orders with a total value greater than $1000. Additionally, filter the results to only include customers who have purchased at least one item with a quantity g... | codefeedback |
Parse the following string and store each key-value pair into a dictionary. The keys should be unique and case-sensitive. The string should only contain alphanumeric characters and the following special characters: !@#$%^&*()-_=+`~[{]}\|;:'",<.>/? Each key-value pair should be separated by a comma and a space. The stri... | codefeedback |
Write a Haskell function to check if two numbers are evenly divisible. The function should return True if the two numbers are evenly divisible and if their sum is greater than 100. Additionally, the function should also return the quotient and remainder when the first number is divided by the second number. | codefeedback |
Construct an SQL query to get the total sales of each customer, as well as the average sales per order for each customer. Additionally, include the total number of items sold for each customer and the most expensive item purchased by each customer.
TABLE customers {
id INT,
name VARCHAR(90)
}
TABLE orders {
... | codefeedback |
Fill in the blank and explain why it works.
The difference between int and float data type is that a float data type stores ____ numerically accurate values with a precision of up to 7 decimal places.
In contrast, int data type stores only whole numbers, while float data type can store both whole numbers and decimal n... | codefeedback |
Construct a for loop to print all the elements of a list numbered in reverse sequence, as shown in the output. Additionally, add a condition to skip printing the element if its length is less than 5.
list_elements = ["apple", "banana", "cherry", "kiwi", "mango"]
Output:
5: mango
4: cherry
3: banana
2: apple | codefeedback |
Create a web application that allows users to register and login. The application should have the following requirements:
1. Registration Page:
- The registration form should include the following fields: first name, last name, email, password, and confirm password.
- The first name and last name fields should only ac... | codefeedback |
How could the following code be optimized?
Write a function that removes duplicates from a given list of integers, without using any additional data structures and without modifying the order of the elements.
Note: The input list may contain negative integers. | codefeedback |
Write a program that prints the sum of all odd numbers between 1 and 100 (inclusive). | codefeedback |
Create a function that sorts a dictionary of words and their frequencies in descending order based on their frequencies. The function should also remove any words that have a frequency less than or equal to 10. Additionally, the function should ignore any words that contain special characters or numbers. | codefeedback |
Compose a SQL query to retrieve the names of all students who have not yet declared a major, have taken at least 2 courses, and have a grade average higher than 80%. | codefeedback |
Write a HTML web page for a registration form with the following requirements:
1. The form should have a heading, paragraph, and a submit button.
2. Implement a character count feature for the name field. Display the current character count next to the input field and restrict the maximum character limit to 30.
3. Add... | codefeedback |
Compose a SQL query to find the number of female students, who are juniors or seniors, whose GPA is greater than 3.5 and are majoring in computer science, and have completed at least 90 credit hours. | codefeedback |
Parse the following JSON string and print out the names of all the objects where the age is greater than 30. Additionally, each object's name should be printed in uppercase letters. The program should also handle cases where the age key is missing in any of the objects.
resp = '[{"name": "john", "age": 25}, {"name": ... | codefeedback |
Add the following Python function to generate a Fibonacci sequence. The function should also handle invalid inputs and return an error message if necessary. Additionally, the function should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Write a code to get the current time in New York City in 24-hour format, without using any built-in date and time libraries or functions. Additionally, ensure that the code handles time zone changes, including daylight saving time. | codefeedback |
Create a function called "removeDuplicates" that takes in an array of integers and removes any duplicate values from the array. The function should return the modified array with the duplicates removed. Additionally, if there are any negative numbers in the array, they should be sorted in descending order before removi... | codefeedback |
Using the "requests" library, write a code to get the data from the endpoint http://jsonplaceholder.typicode.com/users and store it in a MongoDB database. The code should handle concurrent requests and implement proper error handling for network failures. | codefeedback |
Write code to print a multiplication table of prime numbers between 1 and 100, where the table is formatted in a spiral pattern starting from the center. | codefeedback |
Write a code to convert a given English sentence into Pig Latin, but with the following additional rules:
1. If a word starts with a consonant cluster (two or more consonants together), move the cluster to the end of the word and add "ay". For example, "smart" should be converted to "artsmay" and "glove" should be conv... | codefeedback |
Write a SQL query to find the age difference between two people in a table, but only consider the people whose ages are within a certain range and have the same name. Also, consider that the table may contain multiple entries for each person with different ages. The range is defined by two parameters - a minimum age an... | codefeedback |
Generate an SQL statement to select employee Id, name, department, and hire date from the 'Employee' table, but only for employees who have been with the company for more than 5 years, have a salary greater than $50,000, and belong to a department with more than 10 employees. | codefeedback |
Create a tree structure using the provided Python dictionary.
dict = {
1: {
'parent': 0,
'children': [2, 3, 4]
},
2: {
'parent': 1,
'children': []
},
3: {
'parent': 1,
'children': [5, 6]
},
4: {
'parent': 1,
'children': [7]
},
5: {
'parent': 3,
'children': []
... | codefeedback |
Reformat the given C++ code to reduce the memory it needs to function by implementing a custom string concatenation function that operates in-place and doesn't require additional memory allocation. The function should take two character arrays, `str1` and `str2`, and concatenate them without using any built-in string f... | codefeedback |
Generate an HTML table which displays the elements of the array in the form of rows and columns. The array contains multiple strings, where each string represents a row in the table and consists of comma-separated values. The first string in the array represents the table header, and the remaining strings represent the... | codefeedback |
Convert the given program into an asynchronous program using the AsyncIO library in Python. The program should calculate the sum of the given list of numbers, but now each addition should be executed concurrently. Additionally, the program should include error handling for any exceptions that may occur during the execu... | codefeedback |
Implement a function in Python that takes in a list of integers and returns the sum of all prime numbers in the list. You are not allowed to use built-in functions such as sum or any iteration tools such as 'for' or 'while' loops. The time complexity of your solution should be O(n), where n is the length of the input l... | codefeedback |
Create a function to calculate the total cost after N discounts, where N can be up to 10^9.
discounts = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55]
In addition to finding the total cost after N discounts, the function should also return the minimum number of items that need to be purchased to achieve the lowest possible ... | codefeedback |
Create a PHP code snippet to determine the length of a string, but you are not allowed to use the built-in PHP function `strlen()`, `mb_strlen()`, or any other string length functions to calculate the length. | codefeedback |
Write a program that asks the user to enter a list of numbers. The program should continue asking for numbers until the user enters 'done'. Once the user enters 'done', the program should compute and print the average of the numbers entered.
However, if the user enters an invalid number (i.e., a non-numeric value othe... | codefeedback |
Create a function that takes in a list and an index and swaps the elements at the given indices, but only if both elements are prime numbers. Otherwise, return the original list unchanged.
list = [2, 5, 3, 4, 7, 11]
index_1 = 1
index_2 = 5 | codefeedback |
Create a method in Java that takes an integer as input and returns a boolean value indicating whether the number is a prime number or not. Additionally, the method should also handle and return false for any negative input values, zero, and one. | codefeedback |
Create a Python function to swap key-value pairs in a dictionary, but only for keys that start with a vowel and values that are prime numbers. | codefeedback |
Construct a JavaScript function to reverse the characters of a string, without using any built-in string manipulation functions or data structures. The function should have a time complexity of O(n), where n is the length of the string. Additionally, the function should use constant space complexity (O(1)), meaning it ... | codefeedback |
Compare two strings and return "bigger", "smaller" or "equal" depending on the lexicographical order. The comparison should be case-insensitive. Both strings will contain only alphabets and their lengths will be between 1 and 100 (inclusive). Additionally, the comparison should ignore any leading or trailing whitespace... | codefeedback |
Please propose a function that takes a JSON structure as input and returns the total count of all the string values in the structure. The JSON structure can have nested objects and arrays, and the values can be of any type (string, number, boolean, null). The count should only include the string values, and not count a... | codefeedback |
Implement the quick sort algorithm to sort the given array of integers in descending order.
#Misleading Reference Code#
Here is a reference code that implements bubble sort instead of quick sort. Use it as a reference to increase misdirection:
```
def bubble_sort(arr):
n = len(arr)
for i in range(n - 1):
... | codefeedback |
Edit the following code to print out the maximum value from an array of numbers. However, you are not allowed to use any built-in functions or methods that directly find the maximum value.
# Wrong Answer Example #
```python
numbers = [7, 8, 2, 9, 4]
max_value = 0
for num in numbers:
if num > max_value:
ma... | codefeedback |
Create a function that takes two input strings and returns the longest common substring. The function should handle cases where the input strings contain special characters and numeric digits. Additionally, the function should have a time complexity of O(n^2), where n is the length of the longest input string. The func... | codefeedback |
Construct a function to check if a string is a pangram and return the count of each letter in the pangram. The function should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Construct an HTML form to get user input for first name, last name, phone number, email address, and date of birth. Additionally, the form should include validation to ensure that the user enters a valid email address and that the phone number follows a specific format (e.g. ###-###-####). The form should also include ... | codefeedback |
Given an array of integers, implement insertion sort to sort the array in descending order. The array can contain duplicate elements. The algorithm should have a time complexity of O(n^2). | codefeedback |
Calculate the volume of a cuboid given the edges.
Length = 4
Width = 5
Height = 2
Additional Information:
- The length, width, and height of the cuboid are positive integers.
- The length, width, and height of the cuboid are less than or equal to 10^9.
- The program must handle edge cases where the length, width, or h... | codefeedback |
Construct an algorithm to print out the binomial coefficients of a given number n, while also checking if the input is a positive integer. Additionally, the algorithm should be able to handle large numbers efficiently, with a time complexity of O(n) or better. | codefeedback |
Create a program that reads an array of numbers and prints the maximum and minimum values. However, the program should have a time complexity of O(n log n), where n is the number of elements in the array, and should not use any built-in functions for finding the maximum and minimum values. Additionally, the program sho... | codefeedback |
Build a deep learning classifier in Python using the Keras library with a custom loss function and an optimizer other than Adam. Additionally, implement a regularization technique such as dropout or L1/L2 regularization to prevent overfitting. | codefeedback |
Output the top 3 distinct values of the given array in descending order, without using any built-in sorting functions or libraries. The array may contain duplicates. The array should be sorted in O(n) time complexity and O(1) space complexity.
nums = [4, 8, 2, 10, 9, 6, 1, 10, 6, 4, 8] | codefeedback |
Write a query in SQL to select all employees with last name "Smith" and whose age is greater than 30, and whose salary is above the average salary of all employees in the company. | codefeedback |
Suggest an algorithm for checking if a given key exists in a binary search tree in Java with a time complexity of O(log n), where n is the number of nodes in the tree. Additionally, you need to ensure that the algorithm is implemented using a recursive approach rather than an iterative one. | codefeedback |
Write a class in Java to calculate the perimeter and area of a rectangle, while also implementing the following additional functionalities:
1. Allow the user to input the dimensions of the rectangle.
2. Validate that the dimensions are positive integers.
3. Implement a method to calculate the diagonal length of the re... | codefeedback |
Write a Java program that takes a number as input and prints the factorial of that number. The program should include error handling for invalid inputs and should use recursion to calculate the factorial.
The program should also display the intermediate steps of the factorial calculation. For example, if the input num... | codefeedback |
Create a function that takes in a name and returns a string that greets the person by name. The function should also check if the name is in all uppercase letters, and if so, return the greeting in all uppercase letters as well. Additionally, if the name contains any special characters or numbers, the function should r... | codefeedback |
Using data from the Wikipedia API, write a Python program to list the population of India, along with the population densities of its states. Your program should also display the state with the highest population density and the state with the lowest population density. The population density should be calculated as th... | codefeedback |
Sort an array of integers from largest to smallest, ensuring that the time complexity of the sorting algorithm is O(n log n) or better. Additionally, the algorithm should handle duplicate integers correctly, preserving their relative order in the sorted array. | codefeedback |
Write an optimization problem in C++ to minimize the cost of a budget planning problem. Each budget item has a cost and description. The maximum cost constraint is 500. There is also a minimum cost constraint of 50. The budget items can only be selected in multiples of 50. Find the combination of budget items that mini... | codefeedback |
Design and implement a web application that allows users to create and manage their personal task lists. The application should have the following features:
1. User Registration and Login:
- Users should be able to create an account by providing their name, email address, and password.
- Passwords should be secu... | codefeedback |
Write a code to insert a specific element at the beginning of an array and shift all other elements to the right. The array should have a fixed length of 10 and should only store integers between 1 and 100 (inclusive). If the array is already full, the oldest element should be removed before inserting the new element. ... | codefeedback |
Create a class for a car object with properties such as speed, colour, and fuel efficiency. Implement a method that calculates and returns the distance the car can travel with a given amount of fuel. The distance should be calculated based on the car's speed and fuel efficiency. Additionally, implement a method that ch... | codefeedback |
Explain the different scenarios in which a return statement can be encountered in a function, and describe what happens in each case. Additionally, the function should have a time complexity of O(n) and utilize recursion to solve the problem. | codefeedback |
Count the number of times the letter "o" appears in this string, excluding any occurrences within quotation marks. "Hello, Wodr!" | codefeedback |
Generate a function in Python to print all prime numbers in a given range, where the range can be as large as 10^9. Additionally, the function should be optimized to have a time complexity of O(nlog(log(n))), where n is the upper limit of the range.
#Explanation#
To increase the difficulty, we have increased the upper... | codefeedback |
Given an array, write a function that swaps the elements at indices i and j. However, you are not allowed to use a temporary variable to store the value during the swap. The function should modify the array directly.
arr = [3, 5, 7, 4, 9, 2]
#Additional Requirements#
1. Your function should handle cases where the ind... | codefeedback |
Split a given sentence into a list of words. However, each word in the resulting list should be reversed. Additionally, any punctuation marks should be removed from the words before they are reversed.
#Erroneous Code Reference#
def split_sentence(sentence):
return sentence.split()
def remove_punctuation(word):
... | codefeedback |
Generate a Java program for comparing two strings for equality, considering case sensitivity, leading/trailing whitespaces, and the presence of special characters such as punctuation marks and symbols. The program should also handle Unicode characters. | codefeedback |
Create a new Keras model with the given input shape and output layer, but ensure that the model has a custom activation function in one of its hidden layers. Additionally, the model should have a dropout layer with a rate of 0.5 after the custom activation function. The input shape is (10, 20, 3) and the number of clas... | codefeedback |
Explain the concept of immutability in functional programming and how it relates to pure functions. Give examples of impure functions and explain their side effects. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.