instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a Python code to create two empty lists. Then, write a function that takes two lists as parameters and returns a new list containing the elements that are common to both lists. The function should have a time complexity of O(n^2), where n is the length of the longer list. | codefeedback |
Write a C++ code to create a function which prints the sum of two integers, but the function must not use any arithmetic operators (+, -, *, /) or built-in mathematical functions to calculate the sum. Additionally, the function should not use any control flow statements such as if, for, while, or switch to perform the ... | codefeedback |
Create a React component to render a button with a text "Submit" that changes to "Loading..." when clicked, and disables the button until a response is received from an API call. Display an error message if the API call fails.
Additionally, implement the following features:
1. Implement a timeout mechanism so that if... | codefeedback |
Explain the purpose and functionality of the 'except' statement in Python, and provide an example demonstrating its usage in handling exceptions. Additionally, your example should include multiple 'except' statements, each handling a different type of exception, and you should include a final 'except' statement to hand... | codefeedback |
Generate Python code to reverse a string, but you are not allowed to use any built-in string reversal methods or functions. The code should reverse the string character by character using a loop and without creating any new variables. You should also handle special characters and whitespace correctly. Additionally, the... | codefeedback |
Explain the concept of variable scoping in Python and discuss the different types of scopes available. Give examples to illustrate each type of scope. Additionally, explain the concept of closures in Python and provide examples to demonstrate their usage. | codefeedback |
Write a C++ program to separate digits and characters from a string, count the number of occurrences of each character, and display them in descending order of occurrence.
Input string: aabbcc123a
Expected output:
Digits: 123
Characters: aabbcc
Character count (in descending order):
a: 3
b: 2
c: 2 | codefeedback |
Write a JavaScript function that takes an array of integers as input and sorts it in ascending order using the Bubble Sort algorithm. The function should have the following additional steps:
1. Initialize a boolean variable "swapped" to true.
2. Create a while loop that continues as long as "swapped" is true.
3. Insid... | codefeedback |
Generate a random string using 20 characters in Python, where each character must be a lowercase letter. The string should have at least one vowel and one consonant. | codefeedback |
You need to classify an email as spam or not spam. Output "spam" or "not spam".
The email contains multiple paragraphs of text and may include HTML tags. Some spam emails may contain intentionally obfuscated or misspelled words to bypass traditional spam filters. Additionally, the email may include attachments or embe... | codefeedback |
Generate a C program that takes a string as input and prints the ASCII values of all characters in the string, separated by commas. The program should also keep track of the total sum of all ASCII values and print it at the end.
The input string should have a minimum length of 10 characters. Additionally, the program... | codefeedback |
Modify the given Python code to redirect to a different page when the button is clicked. However, instead of using the `button` element, you must use the `a` element with a specific CSS class name: `<a class="custom-link">Visit example.com</a>`. Additionally, you must ensure that the redirection happens only after a su... | codefeedback |
Change the HTML code to open a link in a new tab when the button is clicked. However, the link should only open in a new tab if the user is holding down the "Ctrl" key while clicking the button. Otherwise, the link should open in the same tab. Additionally, the button should change its color to red when the link is ope... | codefeedback |
Write a web application that includes a form with an input field for the user to enter their email address and a submit button. When the submit button is clicked, the application should validate the email address entered by the user. If the email address is valid, the application should redirect the user to another web... | codefeedback |
Design a WebGL program to generate a realistic snowfall effect in the browser.
Requirements:
1. The program should render multiple snowflakes falling from the top of the screen to the bottom.
2. Each snowflake should have a randomized shape, size, and color.
3. The snowflakes should appear to fall at different speeds ... | codefeedback |
How to write a query to select records from a MySQL table titled “Users” that are ordered by the first name in descending order, and also filter out any records where the last name starts with the letter "S"? | codefeedback |
Create a function in PHP that takes a string as input and returns the reversed version of the string with each word capitalized. The function should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Create an array of 10,000 string objects in JavaScript with randomly generated values. Each string value should be a combination of uppercase letters, lowercase letters, and digits, with a length between 5 and 10 characters. Additionally, each string value must contain at least one special character (!,@,#,$,%,&,*,+,=)... | codefeedback |
Write a JavaScript function that redirects the user to a specific URL after a specified amount of time has passed. The function should take two parameters: the URL to redirect to and the duration in milliseconds. The page should automatically redirect to the specified URL after the specified duration has elapsed. Addit... | codefeedback |
Write a function in Java to compute the standard deviation of an array of real numbers. The function should also handle cases where the array may contain missing values represented by NaN. Additionally, the function should return the standard deviation as a rounded integer value. Consider implementing the function with... | codefeedback |
Rewrite the program to efficiently find the Nth prime number in Java. | codefeedback |
Write a code to check if the string has all unique characters in Python.
Additional requirements:
1. The code should have a time complexity of O(n), where n is the length of the string.
2. You cannot use any additional data structures to solve the problem. | codefeedback |
Write a SQL query to find the cities with a population greater than 5 million and an average income higher than $50,000. Additionally, exclude cities where the majority of the population belongs to a specific age group (e.g., under 30 or over 60). | codefeedback |
Rewrite the code in JavaScript to remove the first and last characters from a string, while also converting the remaining characters to uppercase and sorting them in reverse alphabetical order. Additionally, handle cases where the string contains numbers or special characters, and make sure the sorting is case-insensit... | codefeedback |
Create a sorting algorithm in C# which sorts an array of integers in descending order. The algorithm should have a time complexity of O(n log n) and should not use any built-in sorting functions or libraries. The input array may contain duplicate elements and the algorithm should handle this case efficiently. The sorte... | codefeedback |
How to reverse a given string in JavaScript, without using built-in functions or methods, and ensure the code is efficient in terms of time and space complexity? | codefeedback |
Identify the issue in the following function and suggest a fix
You are given a function that is supposed to print the multiplication of a number x with all the numbers from 0 to y-1. However, the function is currently printing the addition of x and y for each iteration. Fix the function so that it correctly prints the ... | codefeedback |
Create a ``Product`` class with the following attributes:
- ``name``: a string representing the name of the product.
- ``price``: a float representing the price of the product.
- ``quantity``: an integer representing the quantity of the product in stock.
The class should also have the following methods:
- ``get_name()... | codefeedback |
Convert the following string ["12.1 10.2 6.3 5.4"] into a list of floats. Additionally, handle the case where the string may contain invalid characters, have missing or extra spaces between numbers, or have multiple strings with similar format within square brackets. The function should also return an error message if ... | codefeedback |
Write a Python program to retrieve the kth smallest element from a given list, where k is an integer greater than or equal to 1 and less than or equal to the length of the list. The list may contain duplicate elements.
For example, given the list [1, 4, 7, 9, 10], and k = 2, the program should return the second smalle... | codefeedback |
You are given a string in Java, and you need to write a program to convert it into a list of characters. Your program should take into account any whitespace characters in the string and preserve their positions in the resulting list.
Write a function named `stringToList` that takes a single parameter:
- `inputString`... | codefeedback |
Write a Python program to convert a given list of lists into a single list, where each element in the single list is the sum of the elements in the corresponding positions of the sublists. The program should also handle cases where the sublists have different lengths and return None in such cases.
input_list = [[1, 2],... | codefeedback |
Sort the given array of integers in increasing order, but you are not allowed to use any built-in sorting functions or libraries. Additionally, the time complexity of your solution should be less than O(n log n). The space complexity should be less than O(log n).
#Justification#
By setting a stricter time complexity r... | codefeedback |
Create an SQL query for selecting names, email addresses, and phone numbers of all users from the user table, sorted alphabetically by their last names. Additionally, include only users who have made at least 3 purchases and have an account created within the last 6 months. | codefeedback |
How would you solve the following problem: Given a list of numbers, find the three numbers that add up to a given sum?
[3, 6, 2, 8, 4], sum = 15
Reference code:
def find_numbers(numbers, target_sum):
# Create a set to store the complement of each number in the list
complements = set()
for i in range(len(nu... | codefeedback |
Using the data provided below, create an SQL query to find the first name, last name, age, and salary of all employees who are between the ages of 35 and 45, and have a salary higher than $50,000. Additionally, order the results by salary in descending order. The query should only consider the employees whose last name... | codefeedback |
Create an array with 20 numbers randomly selected from a range of 0-99, ensuring that each number appears exactly twice. | codefeedback |
Write a Python script to combine two given list of strings, while ensuring that the resulting list does not contain any duplicates.
list1 = ["Python", "Ruby", "JavaScript"]
list2 = ["C++", "C#", "GO"]
In addition to combining the two lists, you need to check if any string in the resulting list is already present, and... | codefeedback |
Write a Python Evaluator to evaluate Python expression using only bitwise operators.
expression = "((5<<1)+3)&(~1)" | codefeedback |
Create a Python program that takes an integer input from the user and prints all prime numbers from 1 to that input number. The program should also calculate and print the sum of all prime numbers within the given range. Additionally, the program should check and ensure that the user input is a positive integer greater... | codefeedback |
Write a SQL query to find customers who have made at least 10 purchases in the last 6 months, are from the states of California or New York, and order the list by their average purchase amount in descending order. Additionally, include the customer's total purchase amount and the number of purchases made by each custom... | codefeedback |
Create a Python script that asks the user to input an integer number greater than 1 and less than 100, and display the sum of all the preceding numbers. Additionally, the program should only allow the user to input a number that is divisible by 3. The program should also validate that the input number is a prime number... | codefeedback |
Create a JavaScript function that takes two parameters, an integer and a character, and returns a string with the character repeated that many times. However, if the character is a number, raise an error stating that the character must be a string. If the integer is negative or greater than 10, raise an error stating t... | codefeedback |
Create an array of 20 random integers in JavaScript between -100 and 100.
After creating the array, remove all the duplicates from it.
Then, sort the array in ascending order.
Finally, calculate the sum of all the even numbers in the array, ensuring that the solution has a time complexity of O(n). | codefeedback |
Write a Python script to extract text from a given PDF page and count the number of unique words in the extracted text. The script should ignore any special characters, punctuation marks, and numbers while counting the words. Additionally, the script should display the top 10 most frequently occurring words in the extr... | codefeedback |
Create a web application using JavaScript and any additional libraries or frameworks of your choice that satisfies the following requirements:
1. The application should display a table with the data provided in the given `data` array.
2. The table should have sortable functionality based on the column headers. Clicki... | codefeedback |
Write a C# method that takes a string and returns the count of unique consecutive characters, but with the following additional conditions:
1. The method should only count alphabetical characters (A-Z, a-z). Any non-alphabetical characters should be ignored.
2. The method should be case-insensitive, meaning that upper... | codefeedback |
Write an SQL query to select the names and ages of all employees whose salary is between 40,000 and 50,000, have been with the company for at least 5 years, and have the letter 'a' in their first name. | codefeedback |
Create a function that converts a given number of seconds into a more readable format of years, months, weeks, days, hours, minutes, and seconds. The function should also handle leap years correctly and provide the correct number of days, hours, minutes, and seconds in each month and year. Additionally, the function sh... | codefeedback |
Create a project in C# to read from a database, apply complex data transformations, and display the results in a table with additional constraints and requirements.
Requirements:
1. Read data from a database table containing information about employees. The table should have the following columns: EmployeeID (int), Fi... | codefeedback |
Create a for loop to iterate through a list of numbers and calculate the sum of all the numbers in the list. However, you are not allowed to use the built-in sum() function. Additionally, you need to implement error handling to handle cases where the list contains non-numeric values.
my_list = [1,2,3,4,5, 'a']
Expect... | codefeedback |
Implement an abstract class named "Shape" with the following requirements:
1. It should have an abstract method named "calculateArea" that returns a float.
2. It should have a concrete method named "printArea" that prints the calculated area of the shape.
3. It should have a constructor that takes two parameters - "len... | codefeedback |
Write a function to construct a new string by appending the provided string to itself, but each character in the original string should be repeated a number of times equal to its position in the original string.
Example:
my_string = 'Hello'
Output: 'Heeellllllooooo' | codefeedback |
Write a Python function that validates a given credit card number and returns the type of the credit card (Visa, MasterCard, American Express, Discover) based on the card number prefix.
You can assume the following card number prefixes:
- Visa: starts with 4 and has a length of 16 digits
- MasterCard: starts with 51, ... | codefeedback |
Write a TensorFlow script to build a 10-layer neural network classifier with dropout regularization.
In addition to building the neural network, please also implement the following:
1. Use a different activation function for each layer (e.g., relu, sigmoid, tanh).
2. Implement batch normalization after each layer.
3. ... | codefeedback |
Create a function that takes in a list of numbers and returns a list of the same numbers, but sorted in a descending order. Additionally, the function should remove any duplicates from the list.
Constraints:
- The length of the list should not exceed 1000 elements.
- The numbers in the list should be integers between ... | codefeedback |
Create an algorithm to detect if a given sentence contains any words or phrases that are offensive. The offensive words and phrases are provided in a list, and they can include special characters and require specific formatting. The algorithm should handle variations in capitalization and punctuation.
Example sentence... | codefeedback |
Write a Python function to return an array of adjacent (horizontal, vertical, and diagonal) numbers of a given two-dimensional array. The function should handle cases where the two-dimensional array is not square.
#Example#
Input:
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Input:
[[1, 2... | codefeedback |
Create a function to count the number of vowels in a string, without using the len() function. Your function should also ignore any whitespace characters in the string. Additionally, your function should be case-sensitive, meaning it should count uppercase and lowercase vowels as different characters. | codefeedback |
Modify the previous code to calculate and print out the total salary of all employees whose salary is between 40,000 and 50,000, whose age is between 30 and 40, and whose department is "Sales". | codefeedback |
Create a function that outputs a nested dictionary from a given list of keys and values. The function should handle cases where the list of keys is nested. The function should also have a time complexity of O(n^2), where n is the length of the input list of keys. The function should also have a space complexity of O(n)... | codefeedback |
Modify the Java program below so that it prints the sum of two given numbers. However, you are not allowed to use the "+" operator, any other arithmetic operator, or any bitwise operation to perform the addition.
int num1 = 3;
int num2 = 5; | codefeedback |
Create a function that returns the `n`th number in the Fibonacci sequence, but with an additional constraint: you cannot use recursion, iteration, or any built-in mathematical functions (such as pow, sqrt, etc.) to solve the problem. You must come up with a solution that uses only basic arithmetic operations and logica... | codefeedback |
Write a SQL query to find the average and median salaries of employees who have been with the company for at least 5 years, have received a performance rating of 4 or higher, and belong to a specific department specified by the user. | codefeedback |
What is the correct command to compile a C++ program on a Linux operating system using g++ compiler with optimization flags enabled and producing a static binary executable? | codefeedback |
Given a comma separated string, write a Python program to convert the string into a list while ignoring any leading or trailing spaces. The program should also handle empty strings gracefully and return an empty list in such cases.
Additionally, the program should check if the input string contains any duplicate eleme... | codefeedback |
Create a responsive HTML page that displays a grid of images fetched from an API. The grid should have a dynamic number of columns based on the screen size, with a maximum of 4 columns. Implement infinite scrolling to load more images when the user reaches the bottom of the page. Additionally, implement a search bar th... | codefeedback |
Parse a given json string and retrieve a dictionary object. The json string may contain nested dictionaries and lists. The dictionary object should only include pets that are older than 2 years. Additionally, the dictionary object should include a new key called "is_adopted" which is set to True for each pet that has b... | codefeedback |
Write a SQL query to list all customers whose phone numbers start with a 6 or 7, have at least one letter in their name, and their total purchase amount is greater than $500. | codefeedback |
Create a function to detect if two given strings are anagrams or not. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. The function should return True if the two strings are anagrams, and False otherwise.
str1 = 'abc'
str2 = 'bac'
# Additional Requirements:
1. The function s... | codefeedback |
Make a class called 'Car' that stores information about a car and contains a function called 'start' which when called, prints out "Car has started". Additionally, add a function called 'accelerate' which takes in a parameter 'speed' and increases the car's speed by that amount.
The 'accelerate' function should also ... | codefeedback |
Write a function that takes in a positive integer and returns the highest prime number that is both a palindrome and can be divided by the given number.
To solve this problem, you can follow these steps:
1. Define a helper function `is_prime(n)` that takes in a positive integer `n` and returns True if it is a prime n... | codefeedback |
Fill in the missing code so that it prints the sum of the second and third elements of each list, and returns a list of the sums. However, you are not allowed to use the '+' operator or any built-in Python function for addition. You can only use bitwise operators and loops.
my_list = [[1,2,3],[4,5,6],[7,8,9]] | codefeedback |
Create a function that takes two strings and removes all the white spaces from them. The function should also remove any leading or trailing spaces. The final strings should be converted to lowercase before being returned. Additionally, the function should check if the input strings are alphanumeric and raise an except... | codefeedback |
Convert a given string to camel case. The input string may contain special characters, numbers, and emojis. Ensure that the camel case string starts with a lowercase letter and does not contain any consecutive duplicate characters. | codefeedback |
What is the return type of a Javascript function that returns the sum of two integers and a string concatenation of two strings, while ensuring that the sum of the integers is a prime number and the length of the concatenated string is greater than 10 characters? | codefeedback |
Implement a code that will group a series of numbers into groups of four, but the grouping should start from the third element in the series.
nums = [1, 2, 3, 4, 5, 6, 7, 8] | codefeedback |
Generate a program to reverse a user inputted string, but without using any built-in string reversal functions or methods. Additionally, the program should ignore any leading or trailing white spaces in the input string.
# Explanation #
1. Prompt the user to input a string.
2. Store the user input in a variable.
3. Re... | codefeedback |
Describe an effective way to debug a complex JavaScript program that involves asynchronous functions, multiple external API calls, and has a time complexity of O(n^2) and space complexity of O(n). | codefeedback |
Implement a function that will return the intersection of two given arrays, while maintaining the order of elements from the first array.
arr_1 = [2,3,4,7,9,10,12]
arr_2 = [1,3, 5, 6, 7, 9, 11, 12, 13]
Additional Requirements:
1. The function should have a time complexity of O(n), where n is the total number of elemen... | codefeedback |
Implement a function that will sort the array using insertion sort.
Write a function named `insertion_sort` that takes in a list of integers called `nums`. The function should sort the list in ascending order using the insertion sort algorithm and return the sorted list.
The insertion sort algorithm works as follows:... | codefeedback |
Write a code that will produce a list containing the sum of the first and last element of each inner list inside a list of lists. The inner lists can contain both positive and negative integers. Additionally, the code should return the sum of the first and last element as a tuple instead of a list. The code should also... | codefeedback |
Create a JavaScript program to validate an IP address, ensuring that it is a valid IPv4 address, that it is not a private IP address, that it is not a reserved IP address, that it is not a multicast IP address, and that it is not a loopback IP address. | codefeedback |
Write a Python script to generate the Fibonacci sequence up to n using a recursive function instead of a loop. Additionally, implement a memoization technique to improve the efficiency of the recursive function.
#Sample Solution# | codefeedback |
Compare two arrays in JavaScript and return true if they have the same elements in the same order, false otherwise. The arrays can contain any type of values, including nested arrays and objects. Additionally, the solution should not use any built-in JavaScript array methods such as 'sort', 'filter', 'includes', or 're... | codefeedback |
Write an SQL query to return the customers whose purchases include productid 100, 101, and 102, and the total quantity of each product purchased must be greater than or equal to 10. Additionally, the query should return the customers in descending order of their total purchase quantity. | codefeedback |
Create a function that takes two strings as arguments and checks if the two strings are anagrams (same letters arranged differently).
The function should perform the following steps:
1. Remove any leading or trailing whitespace from both strings.
2. Convert both strings to lowercase.
3. Remove any non-alphabetic chara... | codefeedback |
Write a code to sort a list of integers from smallest to largest, but without using any built-in sorting functions or algorithms. Additionally, your code should have a time complexity of O(n log n) and a space complexity of O(1). | codefeedback |
Create a loop that prints the values from a and b in ascending order. However, the loop should skip any numbers that are divisible by 3. Additionally, the loop should only print numbers that are also divisible by 2. The loop should terminate if the sum of the printed numbers exceeds 100. The starting values of a and b ... | codefeedback |
Create a function that takes two strings as arguments, and decides if either of them is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward.
The function should first check if both strings are valid and not empty. If either of them is empty or ... | codefeedback |
Write a program that prompts the user to enter a positive integer and determines whether it is a prime number or not. A prime number is a number that is only divisible by 1 and itself.
1. Prompt the user to enter a positive integer.
2. Read and store the input in a variable named "num".
3. Check if the value of "num"... | codefeedback |
Write a function to shift the elements of a list by a specified number of positions to the left.
Example:
shift_list([2, 4, 6, 8], 2) should return [6, 8, 2, 4]
Additional Requirements:
- The function should handle negative shift values, shifting the elements to the right instead.
- The function should handle shift v... | codefeedback |
How can we improve the following model to achieve better performance and accuracy while maintaining a lower time complexity?
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D
model = Sequential()
model.add(Conv2D(128, kernel_size=(5, 5), activation... | codefeedback |
Write a function to parse a given string and construct a dictionary which contains each word and the corresponding frequency. The function should exclude common English stop words such as 'the', 'and', 'or', 'is', 'a', 'how', 'are', 'you', 'doing', 'today', 'weather', 'nice' from the dictionary. The input string may co... | codefeedback |
Write a recursive code that performs binary search on a given sorted list.
my_array = [1,3,5,7,9]
The binary search algorithm should return the index of the target element if it is present in the list, or -1 if it is not present.
Please note the following additional requirements:
1. Your code should have a time com... | codefeedback |
Write a function in Python that takes in a list of integers and returns the sum of the squares of all the even numbers in the list. If any of the numbers in the list is a negative integer, the function should raise a ValueError with the message "Negative integers are not allowed". | codefeedback |
You are given a program that is supposed to calculate the factorial of a given number. However, there are two compile-time errors in the program.
Your task is to resolve these errors and modify the program to correctly calculate the factorial of the given number as follows:
- Declare and initialize a variable 'num' w... | codefeedback |
How can we evaluate a given Python expression dynamically, ensuring that it does not exceed a certain length limit, returns a specific data type, and handles errors and exceptions appropriately? | codefeedback |
Design a class in Java to build a Balanced Binary Search Tree with the following constraints: the height of the tree should not exceed log2(n), where n is the number of elements in the tree, and the average search time for an element should be O(log n). | codefeedback |
How can we remove duplicate elements from a given array while maintaining the original order of elements and without using any additional data structures, with a time complexity of O(n^2)? | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.