instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Create and fill a 2-dimensional list with the dimensions n and m. Each element in the list must be a unique random number between 1 and 100. The sum of all the elements in the list must be greater than 100. n = 3, m = 5 | codefeedback |
Given a string, write a code to find the longest substring without repeating characters and print its length.
Example:
Input: "abcabcbb"
Output: 3
Explanation: The longest substring without repeating characters is "abc", which has a length of 3.
Note:
- The input string can contain any printable ASCII characters.
- T... | codefeedback |
Under the given dictionary, write a code to replace the value at a given key. The key-value pairs in the dictionary should be sorted in ascending order based on the keys. The code should have a time complexity of O(log n) for the search and replacement operation, where n is the number of key-value pairs in the dictiona... | codefeedback |
Calculate the greatest common divisor of 1244 and 867 | codefeedback |
Formulate a MATLAB expression for calculating the sum of the first 1000 natural numbers, but exclude any numbers that are divisible by 3 or 5. | codefeedback |
Write a program in Python that generates a list of all prime numbers within a given range. The program should take two integers as input, representing the start and end of the range, and should output a list of all prime numbers within that range.
Requirements:
- The program should use the range() function to generate... | codefeedback |
Take the following pandas DataFrame, and convert it to a NumPy array. However, you are not allowed to use the pandas library or any built-in functions for conversion. You must write a custom algorithm to perform the conversion. | codefeedback |
Design a stack class for a language of your choice that supports the following operations:
1. push(value): Adds an element to the top of the stack.
2. pop(): Removes and returns the element from the top of the stack.
3. top(): Returns the element from the top of the stack without removing it.
4. is_empty(): Returns a ... | codefeedback |
Execute a valid query using PostgreSQL for finding the title of all movies released in the year 2000, but exclude any movies that have a rating below 7.5. | codefeedback |
Generate a list of all prime divisors of a given number. | codefeedback |
Find the value of a variable in a given environment, considering multiple levels of nested dictionaries and handling potential errors.
env={'key1': 1, 'key2': {'key3': {'key4': 4}}}
variable="key2.key3.key4"
#Additional Step 1#
Check if the variable exists in the environment. If not, handle the error gracefully by ret... | codefeedback |
Implement a quick sort algorithm for a given array list with the following additional requirements:
1. The algorithm should be implemented using recursion.
2. The algorithm should handle duplicate values in the array list.
3. The algorithm should be implemented to work with any data type, not just integers.
4. The alg... | codefeedback |
Given a list of non-negative integers and a target, write an algorithm to determine if the list contains a subset that sums up to the target. The list may contain duplicate numbers.
You should aim to solve this problem with a time complexity of O(2^n) and a space complexity of O(n). | codefeedback |
Design a shell script for sorting the elements of a given array [2, 5, 1, 8, 4] in descending order.
Array elements: [2, 5, 1, 8, 4]
#Erroneous Code Example#
Design a shell script for sorting the elements of a given array [2, 5, 1, 8, 4] in descending order, but the code provided sorts the elements in ascending order. | codefeedback |
Write an SQL statement for creating a table called "movies" with the following columns:
1. id - unique identifier for each movie (integer)
2. title - title of the movie (string)
3. release_date - date of release for the movie (date)
4. genre - genre of the movie (string)
5. director - name of the director (string)
6. d... | codefeedback |
Create a Regex expression that will match strings that contain the word "hello" and are followed by the word "world". The expression should only match if the string also starts with a capital letter and ends with a punctuation mark. | codefeedback |
Create a function in Python that will return the maximum difference between any two numbers present in an array. Additionally, ensure that the function can handle arrays with negative numbers and float values. | codefeedback |
Given a string containing only alphabetic characters and spaces, write a function to reverse the words in the string. The function should ignore any leading or trailing spaces and should also handle multiple consecutive spaces between words. | codefeedback |
Write a code in Java that will get all the prime numbers from an array of integers. | codefeedback |
An array of integers is given, write a function to print the second smallest prime number in the array. | codefeedback |
Construct a loop through this string of characters to check for the letter ‘x’. Report what the loop index was when the letter ‘x’ was found. Additionally, you are required to implement the loop using a while loop instead of a for loop. | codefeedback |
Write an Objective-C program for printing the factorial of a given number.
The program should prompt the user to enter an integer greater than 1 and calculate and print the factorial of that number.
If the user enters a negative number or a decimal number, the program should display an error message and prompt the user... | codefeedback |
Given an array with both negative and positive numbers, create a function to find the smallest positive number that is a multiple of 3 and greater than 5, inside the array. If no such number exists, return -1.
int[] array = {-9, -6, -3, 1, 2, 4, 7, 8, 9}; | codefeedback |
Create a code that creates a 3D array of size 4x4x4, where each element of the array is a randomly generated positive integer between 1 and 1000. The sum of all the elements in the array should be calculated and printed as the final output. | codefeedback |
Create a DynamoDB table called "Users" with a primary key as "UserID" and a sort key as "Username". | codefeedback |
Create a bash script that generates a random 5 letter string with no duplicates in it. The string should consist of only lowercase letters (a-z). | codefeedback |
Create a program that takes two inputs, an array of strings and an array of integers. Output an array with the strings at the same indices as the integers. The integers in the second array represent the indices of the strings in the first array that need to be rearranged.
String[] strings = {"cat", "dog", "bird", "fis... | codefeedback |
Create a machine learning model in Python to predict the total surface area of a cube given its side length and density.
side_length = 3
density = 2.5 | codefeedback |
Design a data structure to store the student details for a school. The data structure should be efficient in terms of memory and time complexity for performing various operations.
1. The data structure should support adding a student's details, including their name, age, grade, and address.
2. It should allow retrievi... | codefeedback |
Write a Ruby function that takes an array of integers as input and returns a new array with only unique elements, without using any built-in Ruby methods or data structures. The function should also handle duplicate elements in the array and maintain the order of the original elements. | codefeedback |
Create a HTML page that takes two text strings as inputs and outputs the longest one. However, you are not allowed to use any built-in functions or methods to find the longest string. You must implement your own algorithm to determine the longest string. | codefeedback |
Compose an R expression to determine the median of a matrix, considering only the values in a specific column. | codefeedback |
Write a MySQL query to select all the products that have a price greater than 10 and are in stock. | codefeedback |
Write a SQL query to generate a table that contains the number of customers per county, sorted in descending order. Additionally, include the percentage of customers each county represents out of the total number of customers. | codefeedback |
Create a function in Python that takes one parameter, a list of integers, and outputs the list in reverse, without using the built-in `reverse()` method or the `[::-1]` slicing syntax. | codefeedback |
You are given a list of numbers. Construct a for loop to filter out the odd numbers from the list. The resulting list should be sorted in ascending order. The original list should remain unchanged.
arr = [9,5,2,7,3] | codefeedback |
Edit this code to fix the bug in the program. The program should now print the longest word(s) in the given list of words. The program should also ignore any words that contain numbers or special characters. The program should be case-insensitive, meaning that it should treat "Hello" and "hello" as the same word. The p... | codefeedback |
Generate a random password of length N (where N is a positive integer) that complies with the following conditions:
1. The password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character.
2. The password must not contain any repeated characters.
3. The password must not c... | codefeedback |
Reverse the words of a given sentence but keep the order of the words intact, while also ensuring that any punctuation marks are preserved in their respective positions.
I am a programmer. | codefeedback |
Create a function to classify the following sentence into "positive", "negative", or "neutral" based on the sentiment conveyed. The function should take into account both the presence of positive or negative words and the overall context of the sentence.
#Additional Context#
Consider expanding the original test by inc... | codefeedback |
Create a script to transpose a matrix.
A matrix is represented as a list of lists, where each inner list represents a row of the matrix. To transpose a matrix, we need to convert its rows into columns and its columns into rows.
Write a function called transpose_matrix(matrix) that takes a matrix as input and returns... | codefeedback |
Create a query that displays the employees who are completed more than 20 years in the company and have received at least one promotion during their tenure. | codefeedback |
Given an array of strings, reverse the order of the elements inside it so that the last string becomes the first and vice versa.
Example:
["hello", "world", "how", "are", "you"] -> ["you", "are", "how", "world", "hello"] | codefeedback |
Find the three elements in a given array that sums up to the target number. | codefeedback |
Create a program to convert a bi-dimensional array into a single array while maintaining the order of the elements. Your program should handle cases where the input array can have up to 100 sub-arrays, and each sub-array can contain up to 1000 elements. The program should also handle cases where the elements in the sub... | codefeedback |
Write a SQL query to list the salary of all employees as a percentage of the salary of the highest paid employee, but only for employees who have been with the company for more than 5 years and have received at least one promotion. | codefeedback |
Parse a string of words and output an array containing only the uppercase words, while maintaining the order of appearance in the original string.
Input:
- A string of words, containing only alphabetic characters and spaces.
- The length of the string is n (1 ≤ n ≤ 10^5).
Output:
- An array of uppercase words, mainta... | codefeedback |
Write a function that takes a sentence as input and returns the reversed version of that sentence. However, the function should ignore any punctuation marks and special characters in the sentence. The function should also handle cases where multiple spaces are present between words.
Example:
Input: "Hello, world!"... | codefeedback |
Output an array with all the prime numbers between 2 and n, inclusive. However, the code provided contains a logical error that needs to be fixed before it can generate the correct output.
#Given Code#
```
def is_prime(num):
if num <= 1:
return False
for i in range(2, num):
if num % i == 0:
... | codefeedback |
Write a program that takes a string as input and outputs the word that has the maximum frequency in the string. In case of multiple words with the same maximum frequency, output the word that occurs first in the string.
For example, given the input string "The sun has set and the moon has risen", the program should ou... | codefeedback |
Given a string, print all its permutations.
Example:
Input: "british"
Output:
"british"
"britsih"
"britihs"
"british"
"britsiih"
...
(Note: The output list will contain all possible permutations of the input string) | codefeedback |
Design a function in Ruby to calculate the exponent of a given base and exponent, without using any built-in Ruby exponentiation methods or operators. | codefeedback |
Design a calculator program using a switch statement that includes the following features:
1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Exponentiation of a number to a given power
6. Square root of a number
Ensure proper validation and error ha... | codefeedback |
Create a lambda function in Python that collects all the numbers between 0 and 100 that are divisible by both 3 and 5. The function should return the sum of all the collected numbers. | codefeedback |
Write a regular expression to match the following sentence: "Mary had a little lamb that followed her everywhere she went and it was very cute." | codefeedback |
Modify the following Keras model to add one 1D convolutional layer before the last layer. Additionally, add a dropout layer after the convolutional layer to prevent overfitting.
model = Sequential()
model.add(Dense(64, activation='relu', input_dim=100))
model.add(Conv1D(32, 3, activation='relu'))
model.add(Dropout(0.5)... | codefeedback |
Write a C++ code snippet to create an infinite loop that calculates the sum of all numbers from 1 to a given positive integer 'n'. | codefeedback |
Write a HTML form to take in two user inputs, validate the inputs, perform a calculation on the inputs, and display the result. | codefeedback |
Using GraphQL, write a query to get name, age, address, and email of all instructors in a training center who have at least 5 years of teaching experience and are certified in at least 3 different programming languages. | codefeedback |
Write a JavaScript function that takes a string as an argument and produces a new string with the duplicated characters removed. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the input string. | codefeedback |
Create a function to take two positive integers and return the larger one. The function should also validate that both input integers are within the range of 1 to 100, inclusive. If any of the integers are outside this range, the function should raise a ValueError with a descriptive error message. | codefeedback |
Write a MySQL query to find the names of all the students who took both math and science classes and achieved a score of at least 80 in both subjects. | codefeedback |
What is the maximum length of a URL as defined in RFC 3986 and what factors can contribute to this limit? Explain how different components of a URL (e.g., scheme, authority, path, query, fragment) can affect the maximum length. Provide examples of URLs that reach or come close to this maximum length. | codefeedback |
Use CSS to create a dark mode version of the following website. Additionally, implement a toggle button that allows users to switch between light mode and dark mode. The toggle button should persist the user's preference across page reloads. | codefeedback |
Update the given JSON array to increment the "age" value of every user by 5 years, but only if the user's name starts with a vowel and their age is less than 40. If the user's name starts with a consonant or their age is 40 or greater, the "age" value should remain unchanged. The updated array should be sorted in desce... | codefeedback |
Using MapReduce, calculate the average age of the users in a given dataset. Additionally, exclude any users who are below the age of 18 from the calculation. | codefeedback |
Write a C++ program that displays the following text, but only if the input string contains a valid email address. | codefeedback |
Create an HTML form with two input fields to take two numbers and a submit button to submit the form. When the form is submitted, use JavaScript to perform the following tasks:
1. Validate that both input fields are not empty. If either input field is empty, display an error message and prevent the form from being sub... | codefeedback |
Write a web scraper using BeautifulSoup to extract a list of tweets from a site.
Target site: https://twitter.com/
Additional requirements:
1. The web scraper should only extract tweets from verified accounts.
2. The extracted tweets should only include those that have been retweeted at least 100 times.
3. The scrape... | codefeedback |
Generate a random string containing 15 lowercase alphabets and 5 random numbers between 0 and 9 using JavaScript. The string should be in a specific format where the letters and numbers are interspersed. For example, the string could be in the format of "a1b2c3d4e5f6g7h8i9j0". | codefeedback |
Create an algorithm for counting the occurrences of a specific character in a string while maintaining a constant space complexity of O(1).
String: "GPT Learning"
Character: "t" | codefeedback |
Construct an SQL query to select the total number of employees in the table 'Employees' and sort the result in descending order based on their salaries. | codefeedback |
Construct an SQL query to delete all records from the table 'Employees' with a given salary. However, the query should also update another table called 'Salaries' to set the salary for these deleted records to 0. | codefeedback |
Develop a Java program that prints all the leap years up to a given year, excluding any years divisible by 100 unless they are also divisible by 400.
Year = 2020 | codefeedback |
Generate pseudocode for a program that takes in an integer and prints out all the prime factors of the given integer. The program should also calculate and print the sum of all the prime factors. Additionally, the program should include error handling to ensure that the input is a positive integer greater than 1. int n... | codefeedback |
Construct an HTML form with five input fields: First Name, Last Name, Username, Password, and Email. The Username field should only allow alphanumeric characters and be case-sensitive. The Password field should have a minimum length of 8 characters and require at least one uppercase letter, one lowercase letter, one nu... | codefeedback |
Write a function in JavaScript that generates a random number between 1 and 10000, inclusive. The function should have a time complexity of O(1). | codefeedback |
Generate a Python code to calculate the compound interest for multiple time periods.
You are given the following inputs:
Principal: the initial amount of money invested (in dollars)
Rate of Interest: the annual interest rate (as a decimal)
Time: the number of years the money is invested for
Write a program that prom... | codefeedback |
Write the SQL query to return a list of unique values from a table called products with a column called categories, but only for products that have a quantity greater than 10 and are priced higher than the average price of all products in the same category. | codefeedback |
Replace every character in a given string with its corresponding ASCII code and reverse the resulting string.
string = "Hello" | codefeedback |
Print all unique combinations of an array of integers, where the combination must include at least two elements and the sum of the elements in each combination must be a prime number.
nums = [1,2,3,4,5] | codefeedback |
Create a program that creates a dictionary containing only the squares of numbers up to n, excluding any perfect squares. Additionally, the program should output the sum of all the squares in the dictionary. n = 10 | codefeedback |
Using a hash table, construct a program to find all of the pairs of an array whose sum is equal to a given target. Additionally, the program should handle duplicate elements in the array and return the count of unique pairs found. The program should also have a time complexity of O(n), where n is the length of the arra... | codefeedback |
Generate a CNN-LSTM model in Keras for image classification with the CIFAR-10 dataset. | codefeedback |
Write a SQL query that returns all records from the "customer" table sorted by first name, but with the following additional conditions:
1. Exclude any records where the first name is empty or null.
2. Group the records by the first letter of the first name, and sort each group by the first name in descending order.
3... | codefeedback |
Create a function to allocate resources to parties, taking into consideration the number of resources each party needs and their priority. The function should return a list of parties in the order they should be allocated resources, based on their priority and the number of available resources.
The function should hav... | codefeedback |
Design an API to pull company data from an external source. Ensure that the API supports authentication and rate limiting to prevent abuse. Additionally, implement error handling to gracefully handle any connection issues or incorrect data returned by the external source. | codefeedback |
Write a query in MySQL to find all records in a table, sorted by a column in descending order, but exclude any records where the value of a specific column is NULL. | codefeedback |
Build a web application that allows users to search for recipes based on ingredients and dietary restrictions. The application should also provide recommendations for alternative ingredients for users with allergies or dietary preferences.
Time Complexity Requirement: The search algorithm should have a time complexity... | codefeedback |
Develop a Python function to calculate a Fibonacci number based on a given index, but without using recursion. | codefeedback |
Update the following code so that it prints the numbers from 0-9 instead of 0-8, but only using a single line of code.
for i in range(9): print(i) | codefeedback |
Create a method in Java that takes in a string and prints its contents in reverse, while ensuring that the method does not use any built-in string manipulation functions such as reverse() or StringBuilder. The method should also handle special characters and whitespace, and should have a time complexity of O(n) and spa... | codefeedback |
Create an Android application with an activity that displays a string "Welcome to Android" and a button below it. When the button is clicked, the text should change to "Hello, World!" and the button should disappear. Additionally, implement a feature where if the user shakes their device, the text changes back to "Welc... | codefeedback |
How would you define a class in Python to represent a college student, with the following attributes: name, age, major, and list of courses enrolled?
Additionally, include the following methods:
1. A method to add a course to the student's list of courses enrolled.
2. A method to remove a course from the student's li... | codefeedback |
Create a PHP script to broadcast a message on a given web page, but with the following additional requirements:
1. The script should be able to handle multiple web page URLs as input.
2. The script should allow the user to specify a delay (in seconds) between each message broadcast.
3. The script should keep track of ... | codefeedback |
In the given JavaScript class, add a method to calculate the area of a square. However, you are not allowed to use the multiplication operator (*) or the power operator (**) to calculate the area. You can only use addition (+), subtraction (-), and division (/) operators. The time complexity of your solution should be ... | codefeedback |
Use Tensorflow to classify a given input dataset of animals as cats, dogs, or birds.
Input dataset contains images of cats, dogs, and birds.
In addition, the classification should be done with an accuracy of at least 95% on a validation set of images.
Furthermore, the model should be able to classify new images in re... | codefeedback |
Suppose you have a dictionary containing the records of some student marks. Write a Python program to calculate the average marks of all the students. The dictionary may contain nested dictionaries representing different subjects and their respective marks for each student.
student_mark_dict = {
'John': {'Math': [... | codefeedback |
Given a string, develop a function to find out how many words are present in it. Each word should be at least 3 characters long and consist only of alphabetic characters. The function should also consider words that have hyphens or apostrophes in them as separate words. The function should ignore any leading or trailin... | codefeedback |
Write a JavaScript code to loop over all elements in a given array and check if each element is a prime number.
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Time Complexity Requirement: O(n * sqrt(m)), where n is the length of the array and m is the maximum element in the array. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.